react-native-quick-crypto 1.0.0-beta.21 → 1.0.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/QuickCrypto.podspec +11 -1
- package/android/CMakeLists.txt +2 -0
- package/cpp/cipher/GCMCipher.cpp +68 -0
- package/cpp/cipher/GCMCipher.hpp +14 -0
- package/cpp/cipher/HybridCipherFactory.hpp +8 -0
- package/cpp/cipher/HybridRsaCipher.cpp +229 -0
- package/cpp/cipher/HybridRsaCipher.hpp +23 -0
- package/cpp/keys/HybridKeyObjectHandle.cpp +508 -9
- package/cpp/keys/HybridKeyObjectHandle.hpp +10 -1
- package/cpp/utils/base64.h +309 -0
- package/lib/commonjs/ec.js +85 -17
- package/lib/commonjs/ec.js.map +1 -1
- package/lib/commonjs/specs/rsaCipher.nitro.js +6 -0
- package/lib/commonjs/specs/rsaCipher.nitro.js.map +1 -0
- package/lib/commonjs/subtle.js +420 -17
- package/lib/commonjs/subtle.js.map +1 -1
- package/lib/commonjs/utils/conversion.js +1 -1
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/module/ec.js +86 -18
- package/lib/module/ec.js.map +1 -1
- package/lib/module/specs/rsaCipher.nitro.js +4 -0
- package/lib/module/specs/rsaCipher.nitro.js.map +1 -0
- package/lib/module/subtle.js +421 -18
- package/lib/module/subtle.js.map +1 -1
- package/lib/module/utils/conversion.js +1 -1
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/ec.d.ts.map +1 -1
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +1 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/rsaCipher.nitro.d.ts +26 -0
- package/lib/typescript/specs/rsaCipher.nitro.d.ts.map +1 -0
- package/lib/typescript/subtle.d.ts.map +1 -1
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/lib/typescript/utils/types.d.ts +1 -1
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +1 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +10 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +10 -0
- package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +104 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +5 -4
- package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp +70 -0
- package/package.json +1 -1
- package/src/ec.ts +122 -20
- package/src/specs/keyObjectHandle.nitro.ts +1 -0
- package/src/specs/rsaCipher.nitro.ts +35 -0
- package/src/subtle.ts +550 -45
- package/src/utils/conversion.ts +3 -1
- package/src/utils/types.ts +6 -6
- package/nitrogen/generated/shared/c++/CFRGKeyPairType.hpp +0 -84
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/*
|
|
2
|
+
base64.h
|
|
3
|
+
|
|
4
|
+
base64 encoding and decoding with C++.
|
|
5
|
+
More information at
|
|
6
|
+
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp
|
|
7
|
+
|
|
8
|
+
Version: 2.rc.09 (release candidate)
|
|
9
|
+
|
|
10
|
+
Copyright (C) 2004-2017, 2020-2022 René Nyffenegger
|
|
11
|
+
|
|
12
|
+
This source code is provided 'as-is', without any express or implied
|
|
13
|
+
warranty. In no event will the author be held liable for any damages
|
|
14
|
+
arising from the use of this software.
|
|
15
|
+
|
|
16
|
+
Permission is granted to anyone to use this software for any purpose,
|
|
17
|
+
including commercial applications, and to alter it and redistribute it
|
|
18
|
+
freely, subject to the following restrictions:
|
|
19
|
+
|
|
20
|
+
1. The origin of this source code must not be misrepresented; you must not
|
|
21
|
+
claim that you wrote the original source code. If you use this source code
|
|
22
|
+
in a product, an acknowledgment in the product documentation would be
|
|
23
|
+
appreciated but is not required.
|
|
24
|
+
|
|
25
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
|
26
|
+
misrepresented as being the original source code.
|
|
27
|
+
|
|
28
|
+
3. This notice may not be removed or altered from any source distribution.
|
|
29
|
+
|
|
30
|
+
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Copyright (C) 2023 Kevin Heifner
|
|
34
|
+
*
|
|
35
|
+
* Modified to be header only.
|
|
36
|
+
* Templated for std::string, std::string_view, std::vector<char> and other char containers.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
#pragma once
|
|
40
|
+
|
|
41
|
+
#include <algorithm>
|
|
42
|
+
#include <stdexcept>
|
|
43
|
+
#include <string>
|
|
44
|
+
#include <string_view>
|
|
45
|
+
|
|
46
|
+
// Interface:
|
|
47
|
+
// Defaults allow for use:
|
|
48
|
+
// std::string s = "foobar";
|
|
49
|
+
// std::string encoded = base64_encode(s);
|
|
50
|
+
// std::string_view sv = "foobar";
|
|
51
|
+
// std::string encoded = base64_encode(sv);
|
|
52
|
+
// std::vector<char> vc = {'f', 'o', 'o'};
|
|
53
|
+
// std::string encoded = base64_encode(vc);
|
|
54
|
+
//
|
|
55
|
+
// Also allows for user provided char containers and specified return types:
|
|
56
|
+
// std::string s = "foobar";
|
|
57
|
+
// std::vector<char> encoded = base64_encode<std::vector<char>>(s);
|
|
58
|
+
|
|
59
|
+
template <typename RetString = std::string, typename String = std::string>
|
|
60
|
+
RetString base64_encode(const String& s, bool url = false);
|
|
61
|
+
|
|
62
|
+
template <typename RetString = std::string, typename String = std::string>
|
|
63
|
+
RetString base64_encode_pem(const String& s);
|
|
64
|
+
|
|
65
|
+
template <typename RetString = std::string, typename String = std::string>
|
|
66
|
+
RetString base64_encode_mime(const String& s);
|
|
67
|
+
|
|
68
|
+
template <typename RetString = std::string, typename String = std::string>
|
|
69
|
+
RetString base64_decode(const String& s, bool remove_linebreaks = false);
|
|
70
|
+
|
|
71
|
+
template <typename RetString = std::string>
|
|
72
|
+
RetString base64_encode(const unsigned char* s, size_t len, bool url = false);
|
|
73
|
+
|
|
74
|
+
namespace detail {
|
|
75
|
+
//
|
|
76
|
+
// Depending on the url parameter in base64_chars, one of
|
|
77
|
+
// two sets of base64 characters needs to be chosen.
|
|
78
|
+
// They differ in their last two characters.
|
|
79
|
+
//
|
|
80
|
+
constexpr const char* to_base64_chars[2] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
81
|
+
"abcdefghijklmnopqrstuvwxyz"
|
|
82
|
+
"0123456789"
|
|
83
|
+
"+/",
|
|
84
|
+
|
|
85
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
86
|
+
"abcdefghijklmnopqrstuvwxyz"
|
|
87
|
+
"0123456789"
|
|
88
|
+
"-_"};
|
|
89
|
+
|
|
90
|
+
constexpr unsigned char from_base64_chars[256] = {
|
|
91
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
92
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 62, 64, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
|
|
93
|
+
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 63,
|
|
94
|
+
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
|
|
95
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
96
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
97
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
98
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64};
|
|
99
|
+
|
|
100
|
+
inline unsigned int pos_of_char(const unsigned char chr) {
|
|
101
|
+
//
|
|
102
|
+
// Return the position of chr within base64_encode()
|
|
103
|
+
//
|
|
104
|
+
|
|
105
|
+
if (from_base64_chars[chr] != 64)
|
|
106
|
+
return from_base64_chars[chr];
|
|
107
|
+
|
|
108
|
+
//
|
|
109
|
+
// 2020-10-23: Throw std::exception rather than const char*
|
|
110
|
+
//(Pablo Martin-Gomez, https://github.com/Bouska)
|
|
111
|
+
//
|
|
112
|
+
throw std::runtime_error("Input is not valid base64-encoded data.");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
template <typename RetString, typename String>
|
|
116
|
+
inline RetString insert_linebreaks(const String& str, size_t distance) {
|
|
117
|
+
//
|
|
118
|
+
// Provided by https://github.com/JomaCorpFX, adapted by Rene & Kevin
|
|
119
|
+
//
|
|
120
|
+
if (!str.size()) {
|
|
121
|
+
return RetString{};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (distance < str.size()) {
|
|
125
|
+
size_t pos = distance;
|
|
126
|
+
String s{str};
|
|
127
|
+
while (pos < s.size()) {
|
|
128
|
+
s.insert(pos, "\n");
|
|
129
|
+
pos += distance + 1;
|
|
130
|
+
}
|
|
131
|
+
return s;
|
|
132
|
+
} else {
|
|
133
|
+
return str;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
template <typename RetString, typename String, unsigned int line_length>
|
|
138
|
+
inline RetString encode_with_line_breaks(String s) {
|
|
139
|
+
return insert_linebreaks<RetString, String>(base64_encode(s, false), line_length);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
template <typename RetString, typename String>
|
|
143
|
+
inline RetString encode_pem(String s) {
|
|
144
|
+
return encode_with_line_breaks<RetString, String, 64>(s);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
template <typename RetString, typename String>
|
|
148
|
+
inline RetString encode_mime(String s) {
|
|
149
|
+
return encode_with_line_breaks<RetString, String, 76>(s);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
template <typename RetString, typename String>
|
|
153
|
+
inline RetString encode(String s, bool url) {
|
|
154
|
+
return base64_encode<RetString>(reinterpret_cast<const unsigned char*>(s.data()), s.size(), url);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
} // namespace detail
|
|
158
|
+
|
|
159
|
+
template <typename RetString>
|
|
160
|
+
inline RetString base64_encode(const unsigned char* bytes_to_encode, size_t in_len, bool url) {
|
|
161
|
+
size_t len_encoded = (in_len + 2) / 3 * 4;
|
|
162
|
+
|
|
163
|
+
const unsigned char trailing_char = '=';
|
|
164
|
+
|
|
165
|
+
//
|
|
166
|
+
// Choose set of base64 characters. They differ
|
|
167
|
+
// for the last two positions, depending on the url
|
|
168
|
+
// parameter.
|
|
169
|
+
// A bool (as is the parameter url) is guaranteed
|
|
170
|
+
// to evaluate to either 0 or 1 in C++ therefore,
|
|
171
|
+
// the correct character set is chosen by subscripting
|
|
172
|
+
// base64_chars with url.
|
|
173
|
+
//
|
|
174
|
+
const char* base64_chars_ = detail::to_base64_chars[url];
|
|
175
|
+
|
|
176
|
+
RetString ret;
|
|
177
|
+
ret.reserve(len_encoded);
|
|
178
|
+
|
|
179
|
+
unsigned int pos = 0;
|
|
180
|
+
|
|
181
|
+
while (pos < in_len) {
|
|
182
|
+
ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0xfc) >> 2]);
|
|
183
|
+
|
|
184
|
+
if (pos + 1 < in_len) {
|
|
185
|
+
ret.push_back(base64_chars_[((bytes_to_encode[pos + 0] & 0x03) << 4) + ((bytes_to_encode[pos + 1] & 0xf0) >> 4)]);
|
|
186
|
+
|
|
187
|
+
if (pos + 2 < in_len) {
|
|
188
|
+
ret.push_back(base64_chars_[((bytes_to_encode[pos + 1] & 0x0f) << 2) + ((bytes_to_encode[pos + 2] & 0xc0) >> 6)]);
|
|
189
|
+
ret.push_back(base64_chars_[bytes_to_encode[pos + 2] & 0x3f]);
|
|
190
|
+
} else {
|
|
191
|
+
ret.push_back(base64_chars_[(bytes_to_encode[pos + 1] & 0x0f) << 2]);
|
|
192
|
+
if (!url)
|
|
193
|
+
ret.push_back(trailing_char);
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0x03) << 4]);
|
|
197
|
+
if (!url)
|
|
198
|
+
ret.push_back(trailing_char);
|
|
199
|
+
if (!url)
|
|
200
|
+
ret.push_back(trailing_char);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
pos += 3;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return ret;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
namespace detail {
|
|
210
|
+
|
|
211
|
+
template <typename RetString, typename String>
|
|
212
|
+
inline RetString decode(const String& encoded_string, bool remove_linebreaks) {
|
|
213
|
+
static_assert(!std::is_same<RetString, std::string_view>::value, "RetString should not be std::string_view");
|
|
214
|
+
|
|
215
|
+
//
|
|
216
|
+
// decode(…) is templated so that it can be used with String = const std::string&
|
|
217
|
+
// or std::string_view (requires at least C++17)
|
|
218
|
+
//
|
|
219
|
+
|
|
220
|
+
if (encoded_string.empty())
|
|
221
|
+
return RetString{};
|
|
222
|
+
|
|
223
|
+
if (remove_linebreaks) {
|
|
224
|
+
String copy{encoded_string};
|
|
225
|
+
|
|
226
|
+
copy.erase(std::remove(copy.begin(), copy.end(), '\n'), copy.end());
|
|
227
|
+
|
|
228
|
+
return base64_decode<RetString, String>(copy, false);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
size_t length_of_string = encoded_string.size();
|
|
232
|
+
size_t pos = 0;
|
|
233
|
+
|
|
234
|
+
//
|
|
235
|
+
// The approximate length (bytes) of the decoded string might be one or
|
|
236
|
+
// two bytes smaller, depending on the amount of trailing equal signs
|
|
237
|
+
// in the encoded string. This approximation is needed to reserve
|
|
238
|
+
// enough space in the string to be returned.
|
|
239
|
+
//
|
|
240
|
+
size_t approx_length_of_decoded_string = length_of_string / 4 * 3;
|
|
241
|
+
RetString ret;
|
|
242
|
+
ret.reserve(approx_length_of_decoded_string);
|
|
243
|
+
|
|
244
|
+
while (pos < length_of_string && encoded_string.at(pos) != '=') {
|
|
245
|
+
//
|
|
246
|
+
// Iterate over encoded input string in chunks. The size of all
|
|
247
|
+
// chunks except the last one is 4 bytes.
|
|
248
|
+
//
|
|
249
|
+
// The last chunk might be padded with equal signs
|
|
250
|
+
// in order to make it 4 bytes in size as well, but this
|
|
251
|
+
// is not required as per RFC 2045.
|
|
252
|
+
//
|
|
253
|
+
// All chunks except the last one produce three output bytes.
|
|
254
|
+
//
|
|
255
|
+
// The last chunk produces at least one and up to three bytes.
|
|
256
|
+
//
|
|
257
|
+
|
|
258
|
+
size_t pos_of_char_1 = pos_of_char(encoded_string.at(pos + 1));
|
|
259
|
+
|
|
260
|
+
//
|
|
261
|
+
// Emit the first output byte that is produced in each chunk:
|
|
262
|
+
//
|
|
263
|
+
ret.push_back(
|
|
264
|
+
static_cast<typename RetString::value_type>(((pos_of_char(encoded_string.at(pos + 0))) << 2) + ((pos_of_char_1 & 0x30) >> 4)));
|
|
265
|
+
|
|
266
|
+
if ((pos + 2 < length_of_string) &&
|
|
267
|
+
// Check for data that is not padded with equal signs (which is allowed by RFC 2045)
|
|
268
|
+
encoded_string.at(pos + 2) != '=') {
|
|
269
|
+
//
|
|
270
|
+
// Emit a chunk's second byte (which might not be produced in the last chunk).
|
|
271
|
+
//
|
|
272
|
+
unsigned int pos_of_char_2 = pos_of_char(encoded_string.at(pos + 2));
|
|
273
|
+
ret.push_back(static_cast<typename RetString::value_type>(((pos_of_char_1 & 0x0f) << 4) + ((pos_of_char_2 & 0x3c) >> 2)));
|
|
274
|
+
|
|
275
|
+
if ((pos + 3 < length_of_string) && encoded_string.at(pos + 3) != '=') {
|
|
276
|
+
//
|
|
277
|
+
// Emit a chunk's third byte (which might not be produced in the last chunk).
|
|
278
|
+
//
|
|
279
|
+
ret.push_back(static_cast<typename RetString::value_type>(((pos_of_char_2 & 0x03) << 6) + pos_of_char(encoded_string.at(pos + 3))));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
pos += 4;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return ret;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
} // namespace detail
|
|
290
|
+
|
|
291
|
+
template <typename RetString, typename String>
|
|
292
|
+
inline RetString base64_decode(const String& s, bool remove_linebreaks) {
|
|
293
|
+
return detail::decode<RetString, String>(s, remove_linebreaks);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
template <typename RetString, typename String>
|
|
297
|
+
inline RetString base64_encode(const String& s, bool url) {
|
|
298
|
+
return detail::encode<RetString, String>(s, url);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
template <typename RetString, typename String>
|
|
302
|
+
inline RetString base64_encode_pem(const String& s) {
|
|
303
|
+
return detail::encode_pem<RetString, String>(s);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
template <typename RetString, typename String>
|
|
307
|
+
inline RetString base64_encode_mime(const String& s) {
|
|
308
|
+
return detail::encode_mime<RetString, String>(s);
|
|
309
|
+
}
|
package/lib/commonjs/ec.js
CHANGED
|
@@ -92,32 +92,100 @@ function ecImportKey(format, keyData, algorithm, extractable, keyUsages) {
|
|
|
92
92
|
if (!namedCurve || !_utils.kNamedCurveAliases[namedCurve]) {
|
|
93
93
|
throw (0, _utils.lazyDOMException)('Unrecognized namedCurve', 'NotSupportedError');
|
|
94
94
|
}
|
|
95
|
+
|
|
96
|
+
// Handle JWK format
|
|
97
|
+
if (format === 'jwk') {
|
|
98
|
+
const jwk = keyData;
|
|
99
|
+
|
|
100
|
+
// Validate JWK
|
|
101
|
+
if (jwk.kty !== 'EC') {
|
|
102
|
+
throw (0, _utils.lazyDOMException)('Invalid JWK "kty" Parameter', 'DataError');
|
|
103
|
+
}
|
|
104
|
+
if (jwk.crv !== namedCurve) {
|
|
105
|
+
throw (0, _utils.lazyDOMException)('JWK "crv" does not match the requested algorithm', 'DataError');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Check use parameter if present
|
|
109
|
+
if (jwk.use !== undefined) {
|
|
110
|
+
const expectedUse = name === 'ECDH' ? 'enc' : 'sig';
|
|
111
|
+
if (jwk.use !== expectedUse) {
|
|
112
|
+
throw (0, _utils.lazyDOMException)('Invalid JWK "use" Parameter', 'DataError');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Check alg parameter if present
|
|
117
|
+
if (jwk.alg !== undefined) {
|
|
118
|
+
let expectedAlg;
|
|
119
|
+
if (name === 'ECDSA') {
|
|
120
|
+
// Map namedCurve to expected ECDSA algorithm
|
|
121
|
+
expectedAlg = namedCurve === 'P-256' ? 'ES256' : namedCurve === 'P-384' ? 'ES384' : namedCurve === 'P-521' ? 'ES512' : undefined;
|
|
122
|
+
} else if (name === 'ECDH') {
|
|
123
|
+
// ECDH uses ECDH-ES algorithm
|
|
124
|
+
expectedAlg = 'ECDH-ES';
|
|
125
|
+
}
|
|
126
|
+
if (expectedAlg && jwk.alg !== expectedAlg) {
|
|
127
|
+
throw (0, _utils.lazyDOMException)('JWK "alg" does not match the requested algorithm', 'DataError');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Import using C++ layer
|
|
132
|
+
const handle = _reactNativeNitroModules.NitroModules.createHybridObject('KeyObjectHandle');
|
|
133
|
+
const keyType = handle.initJwk(jwk, namedCurve);
|
|
134
|
+
if (keyType === undefined) {
|
|
135
|
+
throw (0, _utils.lazyDOMException)('Invalid JWK', 'DataError');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Create the appropriate KeyObject based on type
|
|
139
|
+
let keyObject;
|
|
140
|
+
if (keyType === 1) {
|
|
141
|
+
keyObject = new _keys.PublicKeyObject(handle);
|
|
142
|
+
} else if (keyType === 2) {
|
|
143
|
+
keyObject = new _keys.PrivateKeyObject(handle);
|
|
144
|
+
} else {
|
|
145
|
+
throw (0, _utils.lazyDOMException)('Unexpected key type from JWK import', 'DataError');
|
|
146
|
+
}
|
|
147
|
+
return new _keys.CryptoKey(keyObject, algorithm, keyUsages, extractable);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Handle binary formats (spki, pkcs8, raw)
|
|
95
151
|
if (format !== 'spki' && format !== 'pkcs8' && format !== 'raw') {
|
|
96
152
|
throw (0, _utils.lazyDOMException)(`Unsupported format: ${format}`, 'NotSupportedError');
|
|
97
153
|
}
|
|
98
154
|
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
155
|
+
// Determine expected key type based on format
|
|
156
|
+
const expectedKeyType = format === 'spki' || format === 'raw' ? 'public' : 'private';
|
|
157
|
+
|
|
158
|
+
// Validate usages for the key type
|
|
159
|
+
const isPublicKey = expectedKeyType === 'public';
|
|
160
|
+
let validUsages;
|
|
161
|
+
if (name === 'ECDSA') {
|
|
162
|
+
validUsages = isPublicKey ? ['verify'] : ['sign'];
|
|
163
|
+
} else if (name === 'ECDH') {
|
|
164
|
+
validUsages = isPublicKey ? [] : ['deriveKey', 'deriveBits'];
|
|
165
|
+
} else {
|
|
166
|
+
throw (0, _utils.lazyDOMException)('Unsupported algorithm', 'NotSupportedError');
|
|
167
|
+
}
|
|
168
|
+
if ((0, _utils.hasAnyNotIn)(keyUsages, validUsages)) {
|
|
169
|
+
throw (0, _utils.lazyDOMException)(`Unsupported key usage for a ${name} key`, 'SyntaxError');
|
|
102
170
|
}
|
|
103
171
|
|
|
104
172
|
// Convert keyData to ArrayBuffer
|
|
105
173
|
const keyBuffer = (0, _utils.bufferLikeToArrayBuffer)(keyData);
|
|
106
174
|
|
|
107
|
-
// Create
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
175
|
+
// Create KeyObject directly using the appropriate format
|
|
176
|
+
let keyObject;
|
|
177
|
+
if (format === 'raw') {
|
|
178
|
+
// Raw format is only for public keys - use specialized EC raw import
|
|
179
|
+
const handle = _reactNativeNitroModules.NitroModules.createHybridObject('KeyObjectHandle');
|
|
180
|
+
const curveAlias = _utils.kNamedCurveAliases[namedCurve];
|
|
181
|
+
if (!handle.initECRaw(curveAlias, keyBuffer)) {
|
|
182
|
+
throw (0, _utils.lazyDOMException)('Failed to import EC raw key', 'DataError');
|
|
183
|
+
}
|
|
184
|
+
keyObject = new _keys.PublicKeyObject(handle);
|
|
185
|
+
} else {
|
|
186
|
+
// Use standard DER import for spki/pkcs8
|
|
187
|
+
keyObject = _keys.KeyObject.createKeyObject(expectedKeyType, keyBuffer, 'der', format);
|
|
188
|
+
}
|
|
121
189
|
return new _keys.CryptoKey(keyObject, algorithm, keyUsages, extractable);
|
|
122
190
|
// // // verifyAcceptableEcKeyUse(name, true, usagesSet);
|
|
123
191
|
// // try {
|
package/lib/commonjs/ec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeNitroModules","require","_keys","_utils","Ec","constructor","curve","native","NitroModules","createHybridObject","setCurve","generateKeyPair","publicKey","getPublicKey","privateKey","getPrivateKey","generateKeyPairSync","exports","ecImportKey","format","keyData","algorithm","extractable","keyUsages","name","namedCurve","kNamedCurveAliases","lazyDOMException","
|
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","_keys","_utils","Ec","constructor","curve","native","NitroModules","createHybridObject","setCurve","generateKeyPair","publicKey","getPublicKey","privateKey","getPrivateKey","generateKeyPairSync","exports","ecImportKey","format","keyData","algorithm","extractable","keyUsages","name","namedCurve","kNamedCurveAliases","lazyDOMException","jwk","kty","crv","use","undefined","expectedUse","alg","expectedAlg","handle","keyType","initJwk","keyObject","PublicKeyObject","PrivateKeyObject","CryptoKey","expectedKeyType","isPublicKey","validUsages","hasAnyNotIn","keyBuffer","bufferLikeToArrayBuffer","curveAlias","initECRaw","KeyObject","createKeyObject","ecdsaSignVerify","key","data","hash","signature","isSign","type","hashName","normalizedHashName","normalizeHashName","HashContext","WebCrypto","ec","encoding","KeyEncoding","PKCS8","SPKI","exportKey","KFormatType","DER","importKey","usages","dataBuffer","sign","signatureBuffer","verify","ec_generateKeyPair","_options","Object","keys","includes","publicUsages","privateUsages","getUsagesUnion","keyAlgorithm","publicKeyData","privateKeyData","pub","privateEncoding","priv"],"sourceRoot":"../../src","sources":["ec.ts"],"mappings":";;;;;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAiBA,IAAAE,MAAA,GAAAF,OAAA;AAYO,MAAMG,EAAE,CAAC;EAGdC,WAAWA,CAACC,KAAa,EAAE;IACzB,IAAI,CAACC,MAAM,GAAGC,qCAAY,CAACC,kBAAkB,CAAY,WAAW,CAAC;IACrE,IAAI,CAACF,MAAM,CAACG,QAAQ,CAACJ,KAAK,CAAC;EAC7B;EAEA,MAAMK,eAAeA,CAAA,EAA2B;IAC9C,MAAM,IAAI,CAACJ,MAAM,CAACI,eAAe,CAAC,CAAC;IACnC,OAAO;MACLC,SAAS,EAAE,IAAI,CAACL,MAAM,CAACM,YAAY,CAAC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AS,CAACD,UAAU,EAAEF,SAAS,CAAC,EAAE;MAC5C,MAAM,IAAApB,uBAAgB,EAAC,6BAA6B,EAAE,WAAW,CAAC;IACpE;IACAY,SAAS,GAAG,IAAIC,qBAAe,CAACJ,MAAM,CAAC;EACzC,CAAC,MAAM;IACL;IACAG,SAAS,GAAGY,eAAS,CAACC,eAAe,CACnCT,eAAe,EACfI,SAAS,EACT,KAAK,EACL5B,MACF,CAAC;EACH;EAEA,OAAO,IAAIuB,eAAS,CAACH,SAAS,EAAElB,SAAS,EAAEE,SAAS,EAAED,WAAW,CAAC;EAClE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AACF;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;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;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;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;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACO,MAAM+B,eAAe,GAAGA,CAC7BC,GAAc,EACdC,IAAgB,EAChB;EAAEC;AAAsB,CAAC,EACzBC,SAAsB,KACI;EAC1B,MAAMC,MAAM,GAAGD,SAAS,KAAKzB,SAAS;EACtC,MAAMW,eAAe,GAAGe,MAAM,GAAG,SAAS,GAAG,QAAQ;EAErD,IAAIJ,GAAG,CAACK,IAAI,KAAKhB,eAAe,EAAE;IAChC,MAAM,IAAAhB,uBAAgB,EACpB,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