react-native-quick-crypto 0.7.3 → 1.0.0-beta.2

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 (309) hide show
  1. package/QuickCrypto.podspec +34 -0
  2. package/README.md +13 -46
  3. package/android/CMakeLists.txt +32 -64
  4. package/android/build.gradle +52 -125
  5. package/android/gradle.properties +4 -4
  6. package/android/src/main/cpp/cpp-adapter.cpp +9 -54
  7. package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +38 -0
  8. package/cpp/random/HybridRandom.cpp +34 -0
  9. package/cpp/random/HybridRandom.hpp +44 -0
  10. package/cpp/utils/Utils.hpp +9 -0
  11. package/ios/QuickCryptoOnLoad.mm +19 -0
  12. package/lib/commonjs/index.js +39 -39
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/random.js +26 -12
  15. package/lib/commonjs/random.js.map +1 -1
  16. package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/random.nitro.js} +1 -1
  17. package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/random.nitro.js.map} +1 -1
  18. package/lib/commonjs/utils/conversion.js +22 -0
  19. package/lib/commonjs/utils/conversion.js.map +1 -0
  20. package/lib/commonjs/utils/index.js +12 -0
  21. package/lib/commonjs/utils/index.js.map +1 -0
  22. package/lib/commonjs/utils/types.js +2 -0
  23. package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/utils/types.js.map} +1 -1
  24. package/lib/module/index.js +38 -38
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/random.js +26 -12
  27. package/lib/module/random.js.map +1 -1
  28. package/lib/module/specs/random.nitro.js +4 -0
  29. package/lib/module/{NativeQuickCrypto/rsa.js.map → specs/random.nitro.js.map} +1 -1
  30. package/lib/module/utils/conversion.js +16 -0
  31. package/lib/module/utils/conversion.js.map +1 -0
  32. package/lib/module/utils/index.js +8 -0
  33. package/lib/module/utils/index.js.map +1 -0
  34. package/lib/module/utils/types.js +2 -0
  35. package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/utils/types.js.map} +1 -1
  36. package/lib/tsconfig.tsbuildinfo +1 -0
  37. package/lib/typescript/index.d.ts +10 -141
  38. package/lib/typescript/index.d.ts.map +1 -1
  39. package/lib/typescript/random.d.ts +4 -5
  40. package/lib/typescript/random.d.ts.map +1 -1
  41. package/lib/typescript/specs/random.nitro.d.ts +9 -0
  42. package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
  43. package/lib/typescript/utils/conversion.d.ts +4 -0
  44. package/lib/typescript/utils/conversion.d.ts.map +1 -0
  45. package/lib/typescript/utils/index.d.ts +6 -0
  46. package/lib/typescript/utils/index.d.ts.map +1 -0
  47. package/lib/typescript/utils/types.d.ts +5 -0
  48. package/lib/typescript/utils/types.d.ts.map +1 -0
  49. package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +45 -0
  50. package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +26 -0
  51. package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +57 -0
  52. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +9 -0
  53. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +25 -0
  54. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +29 -0
  55. package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +23 -0
  56. package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +62 -0
  57. package/package.json +50 -106
  58. package/src/index.ts +38 -48
  59. package/src/random.ts +51 -48
  60. package/src/specs/random.nitro.ts +14 -0
  61. package/src/utils/conversion.ts +16 -0
  62. package/src/utils/index.ts +6 -0
  63. package/src/utils/types.ts +15 -0
  64. package/LICENSE +0 -27
  65. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
  66. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
  67. package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
  68. package/cpp/Cipher/MGLCipherHostObject.h +0 -90
  69. package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
  70. package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
  71. package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
  72. package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
  73. package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
  74. package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
  75. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
  76. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
  77. package/cpp/Cipher/MGLPublicCipher.h +0 -124
  78. package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
  79. package/cpp/Cipher/MGLRsa.cpp +0 -573
  80. package/cpp/Cipher/MGLRsa.h +0 -109
  81. package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
  82. package/cpp/HMAC/MGLHmacHostObject.h +0 -39
  83. package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
  84. package/cpp/HMAC/MGLHmacInstaller.h +0 -20
  85. package/cpp/Hash/MGLHashHostObject.cpp +0 -147
  86. package/cpp/Hash/MGLHashHostObject.h +0 -53
  87. package/cpp/Hash/MGLHashInstaller.cpp +0 -44
  88. package/cpp/Hash/MGLHashInstaller.h +0 -20
  89. package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
  90. package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
  91. package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
  92. package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
  93. package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
  94. package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
  95. package/cpp/JSIUtils/MGLTypedArray.cpp +0 -325
  96. package/cpp/JSIUtils/MGLTypedArray.h +0 -160
  97. package/cpp/MGLKeys.cpp +0 -1426
  98. package/cpp/MGLKeys.h +0 -203
  99. package/cpp/MGLQuickCryptoHostObject.cpp +0 -127
  100. package/cpp/MGLQuickCryptoHostObject.h +0 -30
  101. package/cpp/Random/MGLRandomHostObject.cpp +0 -96
  102. package/cpp/Random/MGLRandomHostObject.h +0 -27
  103. package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
  104. package/cpp/Sig/MGLSignHostObjects.h +0 -128
  105. package/cpp/Sig/MGLSignInstaller.cpp +0 -24
  106. package/cpp/Sig/MGLSignInstaller.h +0 -29
  107. package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
  108. package/cpp/Sig/MGLVerifyInstaller.h +0 -22
  109. package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
  110. package/cpp/Utils/MGLDispatchQueue.h +0 -55
  111. package/cpp/Utils/MGLUtils.cpp +0 -295
  112. package/cpp/Utils/MGLUtils.h +0 -358
  113. package/cpp/Utils/base64.h +0 -320
  114. package/cpp/Utils/logs.h +0 -38
  115. package/cpp/Utils/node.h +0 -13
  116. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
  117. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
  118. package/cpp/fastpbkdf2/fastpbkdf2.c +0 -352
  119. package/cpp/fastpbkdf2/fastpbkdf2.h +0 -68
  120. package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
  121. package/cpp/webcrypto/MGLWebCrypto.h +0 -32
  122. package/cpp/webcrypto/crypto_aes.cpp +0 -516
  123. package/cpp/webcrypto/crypto_aes.h +0 -79
  124. package/cpp/webcrypto/crypto_ec.cpp +0 -424
  125. package/cpp/webcrypto/crypto_ec.h +0 -78
  126. package/cpp/webcrypto/crypto_keygen.cpp +0 -86
  127. package/cpp/webcrypto/crypto_keygen.h +0 -38
  128. package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
  129. package/ios/QuickCryptoModule.h +0 -5
  130. package/ios/QuickCryptoModule.mm +0 -42
  131. package/lib/commonjs/Cipher.js +0 -502
  132. package/lib/commonjs/Cipher.js.map +0 -1
  133. package/lib/commonjs/Hash.js +0 -99
  134. package/lib/commonjs/Hash.js.map +0 -1
  135. package/lib/commonjs/Hashnames.js +0 -87
  136. package/lib/commonjs/Hashnames.js.map +0 -1
  137. package/lib/commonjs/Hmac.js +0 -79
  138. package/lib/commonjs/Hmac.js.map +0 -1
  139. package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
  140. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
  141. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -52
  142. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  143. package/lib/commonjs/NativeQuickCrypto/aes.js +0 -6
  144. package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
  145. package/lib/commonjs/NativeQuickCrypto/hash.js.map +0 -1
  146. package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
  147. package/lib/commonjs/NativeQuickCrypto/hmac.js.map +0 -1
  148. package/lib/commonjs/NativeQuickCrypto/keygen.js +0 -6
  149. package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
  150. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
  151. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
  152. package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
  153. package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
  154. package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
  155. package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
  156. package/lib/commonjs/NativeQuickCrypto/webcrypto.js +0 -6
  157. package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
  158. package/lib/commonjs/Utils.js +0 -608
  159. package/lib/commonjs/Utils.js.map +0 -1
  160. package/lib/commonjs/aes.js +0 -281
  161. package/lib/commonjs/aes.js.map +0 -1
  162. package/lib/commonjs/constants.js +0 -85
  163. package/lib/commonjs/constants.js.map +0 -1
  164. package/lib/commonjs/ec.js +0 -276
  165. package/lib/commonjs/ec.js.map +0 -1
  166. package/lib/commonjs/keygen.js +0 -56
  167. package/lib/commonjs/keygen.js.map +0 -1
  168. package/lib/commonjs/keys.js +0 -492
  169. package/lib/commonjs/keys.js.map +0 -1
  170. package/lib/commonjs/pbkdf2.js +0 -90
  171. package/lib/commonjs/pbkdf2.js.map +0 -1
  172. package/lib/commonjs/rsa.js +0 -248
  173. package/lib/commonjs/rsa.js.map +0 -1
  174. package/lib/commonjs/sig.js +0 -129
  175. package/lib/commonjs/sig.js.map +0 -1
  176. package/lib/commonjs/subtle.js +0 -448
  177. package/lib/commonjs/subtle.js.map +0 -1
  178. package/lib/commonjs/webcrypto.js +0 -14
  179. package/lib/commonjs/webcrypto.js.map +0 -1
  180. package/lib/module/Cipher.js +0 -491
  181. package/lib/module/Cipher.js.map +0 -1
  182. package/lib/module/Hash.js +0 -93
  183. package/lib/module/Hash.js.map +0 -1
  184. package/lib/module/Hashnames.js +0 -85
  185. package/lib/module/Hashnames.js.map +0 -1
  186. package/lib/module/Hmac.js +0 -74
  187. package/lib/module/Hmac.js.map +0 -1
  188. package/lib/module/NativeQuickCrypto/Cipher.js +0 -26
  189. package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
  190. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -49
  191. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  192. package/lib/module/NativeQuickCrypto/aes.js +0 -4
  193. package/lib/module/NativeQuickCrypto/hash.js +0 -2
  194. package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
  195. package/lib/module/NativeQuickCrypto/hmac.js +0 -2
  196. package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
  197. package/lib/module/NativeQuickCrypto/keygen.js +0 -4
  198. package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
  199. package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
  200. package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
  201. package/lib/module/NativeQuickCrypto/random.js +0 -2
  202. package/lib/module/NativeQuickCrypto/random.js.map +0 -1
  203. package/lib/module/NativeQuickCrypto/rsa.js +0 -4
  204. package/lib/module/NativeQuickCrypto/sig.js +0 -17
  205. package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
  206. package/lib/module/NativeQuickCrypto/webcrypto.js +0 -4
  207. package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
  208. package/lib/module/Utils.js +0 -539
  209. package/lib/module/Utils.js.map +0 -1
  210. package/lib/module/aes.js +0 -274
  211. package/lib/module/aes.js.map +0 -1
  212. package/lib/module/constants.js +0 -81
  213. package/lib/module/constants.js.map +0 -1
  214. package/lib/module/ec.js +0 -267
  215. package/lib/module/ec.js.map +0 -1
  216. package/lib/module/keygen.js +0 -49
  217. package/lib/module/keygen.js.map +0 -1
  218. package/lib/module/keys.js +0 -477
  219. package/lib/module/keys.js.map +0 -1
  220. package/lib/module/pbkdf2.js +0 -84
  221. package/lib/module/pbkdf2.js.map +0 -1
  222. package/lib/module/rsa.js +0 -242
  223. package/lib/module/rsa.js.map +0 -1
  224. package/lib/module/sig.js +0 -124
  225. package/lib/module/sig.js.map +0 -1
  226. package/lib/module/subtle.js +0 -443
  227. package/lib/module/subtle.js.map +0 -1
  228. package/lib/module/webcrypto.js +0 -10
  229. package/lib/module/webcrypto.js.map +0 -1
  230. package/lib/typescript/Cipher.d.ts +0 -81
  231. package/lib/typescript/Cipher.d.ts.map +0 -1
  232. package/lib/typescript/Hash.d.ts +0 -44
  233. package/lib/typescript/Hash.d.ts.map +0 -1
  234. package/lib/typescript/Hashnames.d.ts +0 -11
  235. package/lib/typescript/Hashnames.d.ts.map +0 -1
  236. package/lib/typescript/Hmac.d.ts +0 -37
  237. package/lib/typescript/Hmac.d.ts.map +0 -1
  238. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -44
  239. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
  240. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
  241. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
  242. package/lib/typescript/NativeQuickCrypto/aes.d.ts +0 -5
  243. package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
  244. package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -7
  245. package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
  246. package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -6
  247. package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
  248. package/lib/typescript/NativeQuickCrypto/keygen.d.ts +0 -4
  249. package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
  250. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +0 -5
  251. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
  252. package/lib/typescript/NativeQuickCrypto/random.d.ts +0 -5
  253. package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
  254. package/lib/typescript/NativeQuickCrypto/rsa.d.ts +0 -5
  255. package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
  256. package/lib/typescript/NativeQuickCrypto/sig.d.ts +0 -23
  257. package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
  258. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +0 -39
  259. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
  260. package/lib/typescript/Utils.d.ts +0 -48
  261. package/lib/typescript/Utils.d.ts.map +0 -1
  262. package/lib/typescript/aes.d.ts +0 -22
  263. package/lib/typescript/aes.d.ts.map +0 -1
  264. package/lib/typescript/constants.d.ts +0 -76
  265. package/lib/typescript/constants.d.ts.map +0 -1
  266. package/lib/typescript/ec.d.ts +0 -7
  267. package/lib/typescript/ec.d.ts.map +0 -1
  268. package/lib/typescript/keygen.d.ts +0 -6
  269. package/lib/typescript/keygen.d.ts.map +0 -1
  270. package/lib/typescript/keys.d.ts +0 -206
  271. package/lib/typescript/keys.d.ts.map +0 -1
  272. package/lib/typescript/pbkdf2.d.ts +0 -12
  273. package/lib/typescript/pbkdf2.d.ts.map +0 -1
  274. package/lib/typescript/rsa.d.ts +0 -12
  275. package/lib/typescript/rsa.d.ts.map +0 -1
  276. package/lib/typescript/sig.d.ts +0 -21
  277. package/lib/typescript/sig.d.ts.map +0 -1
  278. package/lib/typescript/subtle.d.ts +0 -15
  279. package/lib/typescript/subtle.d.ts.map +0 -1
  280. package/lib/typescript/webcrypto.d.ts +0 -9
  281. package/lib/typescript/webcrypto.d.ts.map +0 -1
  282. package/react-native-quick-crypto.podspec +0 -40
  283. package/src/Cipher.ts +0 -832
  284. package/src/Hash.ts +0 -132
  285. package/src/Hashnames.ts +0 -93
  286. package/src/Hmac.ts +0 -106
  287. package/src/NativeQuickCrypto/Cipher.ts +0 -102
  288. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -102
  289. package/src/NativeQuickCrypto/aes.ts +0 -14
  290. package/src/NativeQuickCrypto/hash.ts +0 -10
  291. package/src/NativeQuickCrypto/hmac.ts +0 -9
  292. package/src/NativeQuickCrypto/keygen.ts +0 -7
  293. package/src/NativeQuickCrypto/pbkdf2.ts +0 -16
  294. package/src/NativeQuickCrypto/random.ts +0 -12
  295. package/src/NativeQuickCrypto/rsa.ts +0 -12
  296. package/src/NativeQuickCrypto/sig.ts +0 -44
  297. package/src/NativeQuickCrypto/webcrypto.ts +0 -72
  298. package/src/Utils.ts +0 -777
  299. package/src/aes.ts +0 -402
  300. package/src/constants.ts +0 -79
  301. package/src/ec.ts +0 -375
  302. package/src/keygen.ts +0 -80
  303. package/src/keys.ts +0 -787
  304. package/src/pbkdf2.ts +0 -169
  305. package/src/rsa.ts +0 -370
  306. package/src/sig.ts +0 -164
  307. package/src/subtle.ts +0 -639
  308. package/src/webcrypto.ts +0 -8
  309. /package/android/src/main/{AndroidManifestNew.xml → AndroidManifest.xml} +0 -0
package/src/keys.ts DELETED
@@ -1,787 +0,0 @@
1
- import {
2
- type BinaryLike,
3
- binaryLikeToArrayBuffer,
4
- isStringOrBuffer,
5
- type BufferLike,
6
- type TypedArray,
7
- } from './Utils';
8
- import type { KeyObjectHandle } from './NativeQuickCrypto/webcrypto';
9
- import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
10
- import type { KeyPairKey } from './Cipher';
11
-
12
- export const kNamedCurveAliases = {
13
- 'P-256': 'prime256v1',
14
- 'P-384': 'secp384r1',
15
- 'P-521': 'secp521r1',
16
- } as const;
17
-
18
- export type NamedCurve = 'P-256' | 'P-384' | 'P-521';
19
-
20
- export type ImportFormat = 'raw' | 'pkcs8' | 'spki' | 'jwk';
21
-
22
- export type AnyAlgorithm =
23
- | HashAlgorithm
24
- | KeyPairAlgorithm
25
- | SecretKeyAlgorithm
26
- | SignVerifyAlgorithm
27
- | DeriveBitsAlgorithm
28
- | EncryptDecryptAlgorithm
29
- | 'PBKDF2'
30
- | 'HKDF';
31
-
32
- export type HashAlgorithm =
33
- | 'SHA-1'
34
- | 'SHA-224'
35
- | 'SHA-256'
36
- | 'SHA-384'
37
- | 'SHA-512'
38
- | 'RIPEMD-160';
39
-
40
- export type DigestAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
41
-
42
- export type KeyPairType = 'rsa' | 'rsa-pss' | 'ec';
43
-
44
- export type RSAKeyPairAlgorithm = 'RSASSA-PKCS1-v1_5' | 'RSA-PSS' | 'RSA-OAEP';
45
- export type ECKeyPairAlgorithm = 'ECDSA' | 'ECDH';
46
- export type CFRGKeyPairAlgorithm = 'Ed25519' | 'Ed448' | 'X25519' | 'X448';
47
- export type AESAlgorithm = 'AES-CTR' | 'AES-CBC' | 'AES-GCM' | 'AES-KW';
48
-
49
- export type KeyPairAlgorithm =
50
- | RSAKeyPairAlgorithm
51
- | ECKeyPairAlgorithm
52
- | CFRGKeyPairAlgorithm;
53
-
54
- export type SecretKeyAlgorithm = 'HMAC' | AESAlgorithm;
55
- export type SecretKeyType = 'hmac' | 'aes';
56
-
57
- export type SignVerifyAlgorithm =
58
- | 'RSASSA-PKCS1-v1_5'
59
- | 'RSA-PSS'
60
- | 'ECDSA'
61
- | 'HMAC'
62
- | 'Ed25519'
63
- | 'Ed448';
64
-
65
- export type DeriveBitsAlgorithm =
66
- | 'PBKDF2'
67
- | 'HKDF'
68
- | 'ECDH'
69
- | 'X25519'
70
- | 'X448';
71
-
72
- export type RsaOaepParams = {
73
- name: 'RSA-OAEP';
74
- label?: BufferLike;
75
- };
76
-
77
- export type AesCbcParams = {
78
- name: 'AES-CBC';
79
- iv: BufferLike;
80
- };
81
-
82
- export type AesCtrParams = {
83
- name: 'AES-CTR';
84
- counter: TypedArray;
85
- length: number;
86
- };
87
-
88
- export type AesGcmParams = {
89
- name: 'AES-GCM';
90
- iv: BufferLike;
91
- tagLength?: TagLength;
92
- additionalData?: BufferLike;
93
- };
94
-
95
- export type AesKwParams = {
96
- name: 'AES-KW';
97
- wrappingKey?: BufferLike;
98
- };
99
-
100
- export type AesKeyGenParams = {
101
- length: AESLength;
102
- name?: AESAlgorithm;
103
- };
104
-
105
- export type TagLength = 32 | 64 | 96 | 104 | 112 | 120 | 128;
106
-
107
- export type AESLength = 128 | 192 | 256;
108
-
109
- export type EncryptDecryptParams =
110
- | AesCbcParams
111
- | AesCtrParams
112
- | AesGcmParams
113
- | RsaOaepParams;
114
-
115
- export type EncryptDecryptAlgorithm =
116
- | 'RSA-OAEP'
117
- | 'AES-CTR'
118
- | 'AES-CBC'
119
- | 'AES-GCM';
120
-
121
- export type SubtleAlgorithm = {
122
- name: AnyAlgorithm;
123
- salt?: string;
124
- iterations?: number;
125
- hash?: HashAlgorithm;
126
- namedCurve?: NamedCurve;
127
- length?: number;
128
- modulusLength?: number;
129
- publicExponent?: any;
130
- };
131
-
132
- export type KeyUsage =
133
- | 'encrypt'
134
- | 'decrypt'
135
- | 'sign'
136
- | 'verify'
137
- | 'deriveKey'
138
- | 'deriveBits'
139
- | 'wrapKey'
140
- | 'unwrapKey';
141
-
142
- // On node this value is defined on the native side, for now I'm just creating it here in JS
143
- // TODO(osp) move this into native side to make sure they always match
144
- export enum KFormatType {
145
- kKeyFormatDER,
146
- kKeyFormatPEM,
147
- kKeyFormatJWK,
148
- }
149
-
150
- export type KFormat = 'der' | 'pem' | 'jwk';
151
-
152
- // Same as KFormatType, this enum needs to be defined on the native side
153
- export enum KeyType {
154
- Secret,
155
- Public,
156
- Private,
157
- }
158
-
159
- export type KTypePrivate = 'pkcs1' | 'pkcs8' | 'sec1';
160
- export type KTypePublic = 'pkcs1' | 'spki';
161
- export type KType = KTypePrivate | KTypePublic;
162
-
163
- // Same as KFormatType, this enum needs to be defined on the native side
164
- export enum KWebCryptoKeyFormat {
165
- kWebCryptoKeyFormatRaw,
166
- kWebCryptoKeyFormatPKCS8,
167
- kWebCryptoKeyFormatSPKI,
168
- kWebCryptoKeyFormatJWK,
169
- }
170
-
171
- export enum WebCryptoKeyExportStatus {
172
- OK,
173
- INVALID_KEY_TYPE,
174
- FAILED,
175
- }
176
-
177
- enum KeyInputContext {
178
- kConsumePublic,
179
- kConsumePrivate,
180
- kCreatePublic,
181
- kCreatePrivate,
182
- }
183
-
184
- export enum KeyEncoding {
185
- kKeyEncodingPKCS1,
186
- kKeyEncodingPKCS8,
187
- kKeyEncodingSPKI,
188
- kKeyEncodingSEC1,
189
- }
190
-
191
- export type DSAEncoding = 'der' | 'ieee-p1363';
192
-
193
- export type EncodingOptions = {
194
- key?: any;
195
- type?: KType;
196
- encoding?: string;
197
- dsaEncoding?: DSAEncoding;
198
- format?: KFormat;
199
- padding?: number;
200
- cipher?: string;
201
- passphrase?: string | ArrayBuffer;
202
- saltLength?: number;
203
- };
204
-
205
- export type AsymmetricKeyType = 'rsa' | 'rsa-pss' | 'dsa' | 'ec' | undefined;
206
-
207
- export type JWK = {
208
- 'kty'?: 'AES' | 'RSA' | 'EC' | 'oct';
209
- 'use'?: 'sig' | 'enc';
210
- 'key_ops'?: KeyUsage[];
211
- 'alg'?: string; // TODO: enumerate these (RFC-7517)
212
- 'crv'?: string;
213
- 'kid'?: string;
214
- 'x5u'?: string;
215
- 'x5c'?: string[];
216
- 'x5t'?: string;
217
- 'x5t#256'?: string;
218
- 'n'?: string;
219
- 'e'?: string;
220
- 'd'?: string;
221
- 'p'?: string;
222
- 'q'?: string;
223
- 'x'?: string;
224
- 'y'?: string;
225
- 'k'?: string;
226
- 'dp'?: string;
227
- 'dq'?: string;
228
- 'qi'?: string;
229
- 'ext'?: boolean;
230
- };
231
-
232
- const encodingNames = {
233
- [KeyEncoding.kKeyEncodingPKCS1]: 'pkcs1',
234
- [KeyEncoding.kKeyEncodingPKCS8]: 'pkcs8',
235
- [KeyEncoding.kKeyEncodingSPKI]: 'spki',
236
- [KeyEncoding.kKeyEncodingSEC1]: 'sec1',
237
- };
238
-
239
- export type CryptoKeyPair = {
240
- publicKey: KeyPairKey;
241
- privateKey: KeyPairKey;
242
- };
243
-
244
- export enum CipherOrWrapMode {
245
- kWebCryptoCipherEncrypt,
246
- kWebCryptoCipherDecrypt,
247
- // kWebCryptoWrapKey,
248
- // kWebCryptoUnwrapKey,
249
- }
250
-
251
- function option(name: string, objName: string | undefined) {
252
- return objName === undefined
253
- ? `options.${name}`
254
- : `options.${objName}.${name}`;
255
- }
256
-
257
- function parseKeyFormat(
258
- formatStr: string | undefined,
259
- defaultFormat: KFormatType | undefined,
260
- optionName?: string
261
- ) {
262
- if (formatStr === undefined && defaultFormat !== undefined)
263
- return defaultFormat;
264
- else if (formatStr === 'pem') return KFormatType.kKeyFormatPEM;
265
- else if (formatStr === 'der') return KFormatType.kKeyFormatDER;
266
- else if (formatStr === 'jwk') return KFormatType.kKeyFormatJWK;
267
- throw new Error(`Invalid key format str: ${optionName}`);
268
- // throw new ERR_INVALID_ARG_VALUE(optionName, formatStr);
269
- }
270
-
271
- function parseKeyType(
272
- typeStr: string | undefined,
273
- required: boolean,
274
- keyType: string | undefined,
275
- isPublic: boolean | undefined,
276
- optionName: string
277
- ): KeyEncoding | undefined {
278
- if (typeStr === undefined && !required) {
279
- return undefined;
280
- } else if (typeStr === 'pkcs1') {
281
- if (keyType !== undefined && keyType !== 'rsa') {
282
- throw new Error(
283
- `Crypto incompatible key options: ${typeStr} can only be used for RSA keys`
284
- );
285
- }
286
- return KeyEncoding.kKeyEncodingPKCS1;
287
- } else if (typeStr === 'spki' && isPublic !== false) {
288
- return KeyEncoding.kKeyEncodingSPKI;
289
- } else if (typeStr === 'pkcs8' && isPublic !== true) {
290
- return KeyEncoding.kKeyEncodingPKCS8;
291
- } else if (typeStr === 'sec1' && isPublic !== true) {
292
- if (keyType !== undefined && keyType !== 'ec') {
293
- throw new Error(
294
- `Incompatible key options ${typeStr} can only be used for EC keys`
295
- );
296
- }
297
- return KeyEncoding.kKeyEncodingSEC1;
298
- }
299
-
300
- throw new Error(`Invalid option ${optionName} - ${typeStr}`);
301
- }
302
-
303
- function parseKeyFormatAndType(
304
- enc: EncodingOptions,
305
- keyType?: string,
306
- isPublic?: boolean,
307
- objName?: string
308
- ) {
309
- const { format: formatStr, type: typeStr } = enc;
310
-
311
- const isInput = keyType === undefined;
312
- const format = parseKeyFormat(
313
- formatStr,
314
- isInput ? KFormatType.kKeyFormatPEM : undefined,
315
- option('format', objName)
316
- );
317
-
318
- const isRequired =
319
- (!isInput || format === KFormatType.kKeyFormatDER) &&
320
- format !== KFormatType.kKeyFormatJWK;
321
-
322
- const type = parseKeyType(
323
- typeStr,
324
- isRequired,
325
- keyType,
326
- isPublic,
327
- option('type', objName)
328
- );
329
- return { format, type };
330
- }
331
-
332
- function parseKeyEncoding(
333
- enc: EncodingOptions,
334
- keyType?: string,
335
- isPublic?: boolean,
336
- objName?: string
337
- ) {
338
- // validateObject(enc, 'options');
339
-
340
- const isInput = keyType === undefined;
341
-
342
- const { format, type } = parseKeyFormatAndType(
343
- enc,
344
- keyType,
345
- isPublic,
346
- objName
347
- );
348
-
349
- let cipher, passphrase, encoding;
350
- if (isPublic !== true) {
351
- ({ cipher, passphrase, encoding } = enc);
352
-
353
- if (!isInput) {
354
- if (cipher != null) {
355
- if (typeof cipher !== 'string')
356
- throw new Error(
357
- `Invalid argument ${option('cipher', objName)}: ${cipher}`
358
- );
359
- if (
360
- format === KFormatType.kKeyFormatDER &&
361
- (type === KeyEncoding.kKeyEncodingPKCS1 ||
362
- type === KeyEncoding.kKeyEncodingSEC1)
363
- ) {
364
- throw new Error(
365
- `Incompatible key options ${encodingNames[type]} does not support encryption`
366
- );
367
- }
368
- } else if (passphrase !== undefined) {
369
- throw new Error(
370
- `invalid argument ${option('cipher', objName)}: ${cipher}`
371
- );
372
- }
373
- }
374
-
375
- if (
376
- (isInput && passphrase !== undefined && !isStringOrBuffer(passphrase)) ||
377
- (!isInput && cipher != null && !isStringOrBuffer(passphrase))
378
- ) {
379
- throw new Error(
380
- `Invalid argument value ${option('passphrase', objName)}: ${passphrase}`
381
- );
382
- }
383
- }
384
-
385
- if (passphrase !== undefined)
386
- passphrase = binaryLikeToArrayBuffer(passphrase, encoding);
387
-
388
- return { format, type, cipher, passphrase };
389
- }
390
-
391
- function prepareAsymmetricKey(
392
- key: BinaryLike | EncodingOptions,
393
- ctx: KeyInputContext
394
- ): {
395
- format: KFormatType;
396
- data: ArrayBuffer;
397
- type?: KeyEncoding;
398
- passphrase?: string | ArrayBuffer;
399
- } {
400
- // TODO(osp) check, KeyObject some node object
401
- // if (isKeyObject(key)) {
402
- // // Best case: A key object, as simple as that.
403
- // return { data: getKeyObjectHandle(key, ctx) };
404
- // } else
405
- // if (isCryptoKey(key)) {
406
- // return { data: getKeyObjectHandle(key[kKeyObject], ctx) };
407
- // } else
408
- if (isStringOrBuffer(key)) {
409
- // Expect PEM by default, mostly for backward compatibility.
410
- return {
411
- format: KFormatType.kKeyFormatPEM,
412
- data: binaryLikeToArrayBuffer(key),
413
- };
414
- } else if (typeof key === 'object') {
415
- const { key: data, encoding } = key;
416
- // // The 'key' property can be a KeyObject as well to allow specifying
417
- // // additional options such as padding along with the key.
418
- // if (isKeyObject(data)) {
419
- // return { data: getKeyObjectHandle(data, ctx) };
420
- // }
421
- // else if (isCryptoKey(data))
422
- // return { data: getKeyObjectHandle(data[kKeyObject], ctx) };
423
- // else if (isJwk(data) && format === 'jwk')
424
- // return { data: getKeyObjectHandleFromJwk(data, ctx), format: 'jwk' };
425
- // Either PEM or DER using PKCS#1 or SPKI.
426
- if (!isStringOrBuffer(data)) {
427
- throw new Error(
428
- 'prepareAsymmetricKey: key is not a string or ArrayBuffer'
429
- );
430
- }
431
-
432
- const isPublic =
433
- ctx === KeyInputContext.kConsumePrivate ||
434
- ctx === KeyInputContext.kCreatePrivate
435
- ? false
436
- : undefined;
437
-
438
- return {
439
- data: binaryLikeToArrayBuffer(data, encoding),
440
- ...parseKeyEncoding(key, undefined, isPublic),
441
- };
442
- }
443
-
444
- throw new Error('[prepareAsymetricKey] Invalid argument key: ${key}');
445
- }
446
-
447
- // TODO(osp) any here is a node KeyObject
448
- export function preparePrivateKey(key: BinaryLike | EncodingOptions) {
449
- return prepareAsymmetricKey(key, KeyInputContext.kConsumePrivate);
450
- }
451
-
452
- // TODO(osp) any here is a node KeyObject
453
- export function preparePublicOrPrivateKey(key: BinaryLike | EncodingOptions) {
454
- return prepareAsymmetricKey(key, KeyInputContext.kConsumePublic);
455
- }
456
-
457
- // Parses the public key encoding based on an object. keyType must be undefined
458
- // when this is used to parse an input encoding and must be a valid key type if
459
- // used to parse an output encoding.
460
- export function parsePublicKeyEncoding(
461
- enc: EncodingOptions,
462
- keyType: string | undefined,
463
- objName?: string
464
- ) {
465
- return parseKeyEncoding(enc, keyType, keyType ? true : undefined, objName);
466
- }
467
-
468
- // Parses the private key encoding based on an object. keyType must be undefined
469
- // when this is used to parse an input encoding and must be a valid key type if
470
- // used to parse an output encoding.
471
- export function parsePrivateKeyEncoding(
472
- enc: EncodingOptions,
473
- keyType: string | undefined,
474
- objName?: string
475
- ) {
476
- return parseKeyEncoding(enc, keyType, false, objName);
477
- }
478
-
479
- // function getKeyObjectHandle(key: any, ctx: KeyInputContext) {
480
- // if (ctx === KeyInputContext.kConsumePublic) {
481
- // throw new Error(
482
- // 'Invalid argument type for "key". Need ArrayBuffer, TypeArray, KeyObject, CryptoKey, string'
483
- // );
484
- // }
485
-
486
- // if (key.type !== 'private') {
487
- // if (
488
- // ctx === KeyInputContext.kConsumePrivate ||
489
- // ctx === KeyInputContext.kCreatePublic
490
- // )
491
- // throw new Error(`Invalid KeyObject type: ${key.type}, expected 'public'`);
492
- // if (key.type !== 'public') {
493
- // throw new Error(
494
- // `Invalid KeyObject type: ${key.type}, expected 'private' or 'public'`
495
- // );
496
- // }
497
- // }
498
-
499
- // return key.handle;
500
- // }
501
-
502
- function prepareSecretKey(
503
- key: BinaryLike,
504
- encoding?: string,
505
- bufferOnly = false
506
- ): any {
507
- try {
508
- if (!bufferOnly) {
509
- // TODO: maybe use `key.constructor.name === 'KeyObject'` ?
510
- if (key instanceof KeyObject) {
511
- if (key.type !== 'secret')
512
- throw new Error(
513
- `invalid KeyObject type: ${key.type}, expected 'secret'`
514
- );
515
- return key.handle;
516
- }
517
- // TODO: maybe use `key.constructor.name === 'CryptoKey'` ?
518
- else if (key instanceof CryptoKey) {
519
- if (key.type !== 'secret')
520
- throw new Error(
521
- `invalid CryptoKey type: ${key.type}, expected 'secret'`
522
- );
523
- return key.keyObject.handle;
524
- }
525
- }
526
-
527
- if (key instanceof ArrayBuffer) {
528
- return key;
529
- }
530
-
531
- return binaryLikeToArrayBuffer(key, encoding);
532
- } catch (error) {
533
- throw new Error(
534
- 'Invalid argument type for "key". Need ArrayBuffer, TypedArray, KeyObject, CryptoKey, string',
535
- { cause: error }
536
- );
537
- }
538
- }
539
-
540
- export function createSecretKey(key: any, encoding?: string) {
541
- const k = prepareSecretKey(key, encoding, true);
542
- const handle = NativeQuickCrypto.webcrypto.createKeyObjectHandle();
543
- handle.init(KeyType.Secret, k);
544
- return new SecretKeyObject(handle);
545
- }
546
-
547
- export function createPublicKey(
548
- key: BinaryLike | EncodingOptions
549
- ): PublicKeyObject {
550
- const { format, type, data, passphrase } = prepareAsymmetricKey(
551
- key,
552
- KeyInputContext.kCreatePublic
553
- );
554
- const handle = NativeQuickCrypto.webcrypto.createKeyObjectHandle();
555
- if (format === KFormatType.kKeyFormatJWK) {
556
- handle.init(KeyType.Public, data);
557
- } else {
558
- handle.init(KeyType.Public, data, format, type, passphrase);
559
- }
560
- return new PublicKeyObject(handle);
561
- }
562
-
563
- export const createPrivateKey = (
564
- key: BinaryLike | EncodingOptions
565
- ): PrivateKeyObject => {
566
- const { format, type, data, passphrase } = prepareAsymmetricKey(
567
- key,
568
- KeyInputContext.kCreatePrivate
569
- );
570
- const handle = NativeQuickCrypto.webcrypto.createKeyObjectHandle();
571
- if (format === KFormatType.kKeyFormatJWK) {
572
- handle.init(KeyType.Private, data);
573
- } else {
574
- handle.init(KeyType.Private, data, format, type, passphrase);
575
- }
576
- return new PrivateKeyObject(handle);
577
- };
578
-
579
- // const isKeyObject = (obj: any): obj is KeyObject => {
580
- // return obj != null && obj.keyType !== undefined;
581
- // };
582
-
583
- export class CryptoKey {
584
- keyObject: KeyObject;
585
- keyAlgorithm: SubtleAlgorithm;
586
- keyUsages: KeyUsage[];
587
- keyExtractable: boolean;
588
-
589
- constructor(
590
- keyObject: KeyObject,
591
- keyAlgorithm: SubtleAlgorithm,
592
- keyUsages: KeyUsage[],
593
- keyExtractable: boolean
594
- ) {
595
- this.keyObject = keyObject;
596
- this.keyAlgorithm = keyAlgorithm;
597
- this.keyUsages = keyUsages;
598
- this.keyExtractable = keyExtractable;
599
- }
600
-
601
- inspect(_depth: number, _options: any): any {
602
- throw new Error('CryptoKey.inspect is not implemented');
603
- // if (depth < 0) return this;
604
-
605
- // const opts = {
606
- // ...options,
607
- // depth: options.depth == null ? null : options.depth - 1,
608
- // };
609
-
610
- // return `CryptoKey ${inspect(
611
- // {
612
- // type: this.type,
613
- // extractable: this.extractable,
614
- // algorithm: this.algorithm,
615
- // usages: this.usages,
616
- // },
617
- // opts
618
- // )}`;
619
- }
620
-
621
- get type() {
622
- // if (!(this instanceof CryptoKey)) throw new Error('Invalid CryptoKey');
623
- return this.keyObject.type;
624
- }
625
-
626
- get extractable() {
627
- return this.keyExtractable;
628
- }
629
-
630
- get algorithm() {
631
- return this.keyAlgorithm;
632
- }
633
-
634
- get usages() {
635
- return this.keyUsages;
636
- }
637
- }
638
-
639
- class KeyObject {
640
- handle: KeyObjectHandle;
641
- type: 'public' | 'secret' | 'private' | 'unknown' = 'unknown';
642
- export(_options?: EncodingOptions): ArrayBuffer {
643
- return new ArrayBuffer(0);
644
- }
645
-
646
- constructor(type: string, handle: KeyObjectHandle) {
647
- if (type !== 'secret' && type !== 'public' && type !== 'private')
648
- throw new Error(`invalid KeyObject type: ${type}`);
649
- this.handle = handle;
650
- this.type = type;
651
- }
652
-
653
- // get type(): string {
654
- // return this.type;
655
- // }
656
-
657
- // static from(key) {
658
- // if (!isCryptoKey(key))
659
- // throw new ERR_INVALID_ARG_TYPE('key', 'CryptoKey', key);
660
- // return key[kKeyObject];
661
- // }
662
-
663
- // equals(otherKeyObject) {
664
- // if (!isKeyObject(otherKeyObject)) {
665
- // throw new ERR_INVALID_ARG_TYPE(
666
- // 'otherKeyObject',
667
- // 'KeyObject',
668
- // otherKeyObject
669
- // );
670
- // }
671
-
672
- // return (
673
- // otherKeyObject.type === this.type &&
674
- // this[kHandle].equals(otherKeyObject[kHandle])
675
- // );
676
- // }
677
- }
678
-
679
- export class SecretKeyObject extends KeyObject {
680
- constructor(handle: KeyObjectHandle) {
681
- super('secret', handle);
682
- }
683
-
684
- // get symmetricKeySize() {
685
- // return this[kHandle].getSymmetricKeySize();
686
- // }
687
-
688
- export(options?: EncodingOptions) {
689
- if (options !== undefined) {
690
- if (options.format === 'jwk') {
691
- throw new Error('SecretKey export for jwk is not implemented');
692
- // return this.handle.exportJwk({}, false);
693
- }
694
- }
695
- return this.handle.export();
696
- }
697
- }
698
-
699
- // const kAsymmetricKeyType = Symbol('kAsymmetricKeyType');
700
- // const kAsymmetricKeyDetails = Symbol('kAsymmetricKeyDetails');
701
-
702
- // function normalizeKeyDetails(details = {}) {
703
- // if (details.publicExponent !== undefined) {
704
- // return {
705
- // ...details,
706
- // publicExponent: bigIntArrayToUnsignedBigInt(
707
- // new Uint8Array(details.publicExponent)
708
- // ),
709
- // };
710
- // }
711
- // return details;
712
- // }
713
-
714
- class AsymmetricKeyObject extends KeyObject {
715
- constructor(type: string, handle: KeyObjectHandle) {
716
- super(type, handle);
717
- }
718
-
719
- private _asymmetricKeyType?: AsymmetricKeyType;
720
-
721
- get asymmetricKeyType(): AsymmetricKeyType {
722
- if (!this._asymmetricKeyType) {
723
- this._asymmetricKeyType = this.handle.getAsymmetricKeyType();
724
- }
725
- return this._asymmetricKeyType;
726
- }
727
-
728
- // get asymmetricKeyDetails() {
729
- // switch (this._asymmetricKeyType) {
730
- // case 'rsa':
731
- // case 'rsa-pss':
732
- // case 'dsa':
733
- // case 'ec':
734
- // return (
735
- // this[kAsymmetricKeyDetails] ||
736
- // (this[kAsymmetricKeyDetails] = normalizeKeyDetails(
737
- // this[kHandle].keyDetail({})
738
- // ))
739
- // );
740
- // default:
741
- // return {};
742
- // }
743
- // }
744
- }
745
-
746
- export class PublicKeyObject extends AsymmetricKeyObject {
747
- constructor(handle: KeyObjectHandle) {
748
- super('public', handle);
749
- }
750
-
751
- export(options: EncodingOptions) {
752
- if (options?.format === 'jwk') {
753
- throw new Error('PublicKey export for jwk is not implemented');
754
- // return this.handle.exportJwk({}, false);
755
- }
756
- const { format, type } = parsePublicKeyEncoding(
757
- options,
758
- this.asymmetricKeyType
759
- );
760
- return this.handle.export(format, type);
761
- }
762
- }
763
-
764
- export class PrivateKeyObject extends AsymmetricKeyObject {
765
- constructor(handle: KeyObjectHandle) {
766
- super('private', handle);
767
- }
768
-
769
- export(options: EncodingOptions) {
770
- if (options?.format === 'jwk') {
771
- if (options.passphrase !== undefined) {
772
- throw new Error('jwk does not support encryption');
773
- }
774
- throw new Error('PrivateKey export for jwk is not implemented');
775
- // return this.handle.exportJwk({}, false);
776
- }
777
- const { format, type, cipher, passphrase } = parsePrivateKeyEncoding(
778
- options,
779
- this.asymmetricKeyType
780
- );
781
- return this.handle.export(format, type, cipher, passphrase);
782
- }
783
- }
784
-
785
- export const isCryptoKey = (obj: any): boolean => {
786
- return obj !== null && obj?.keyObject !== undefined;
787
- };