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
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["NativeQuickCrypto/pbkdf2.ts"],"mappings":"","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["NativeQuickCrypto/random.ts"],"mappings":"","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["NativeQuickCrypto/sig.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=webcrypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["NativeQuickCrypto/webcrypto.ts"],"mappings":"","ignoreList":[]}
@@ -4,26 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.QuickCrypto = void 0;
7
-
8
7
  var pbkdf2 = _interopRequireWildcard(require("./pbkdf2"));
9
-
10
8
  var random = _interopRequireWildcard(require("./random"));
11
-
12
9
  var _Cipher = require("./Cipher");
13
-
14
10
  var _sig = require("./sig");
15
-
16
11
  var _Hmac = require("./Hmac");
17
-
18
12
  var _Hash = require("./Hash");
19
-
20
13
  var _constants = require("./constants");
21
-
22
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
-
24
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
-
26
- const QuickCrypto = {
14
+ var _subtle = require("./subtle");
15
+ var _Utils = require("./Utils");
16
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
+ const QuickCrypto = exports.QuickCrypto = {
27
19
  createHmac: _Hmac.createHmac,
28
20
  Hmac: _Hmac.createHmac,
29
21
  Hash: _Hash.createHash,
@@ -39,9 +31,11 @@ const QuickCrypto = {
39
31
  generateKeyPairSync: _Cipher.generateKeyPairSync,
40
32
  createSign: _sig.createSign,
41
33
  createVerify: _sig.createVerify,
34
+ subtle: _subtle.subtle,
42
35
  constants: _constants.constants,
43
36
  ...pbkdf2,
44
- ...random
37
+ ...random,
38
+ getCiphers: _Utils.getCiphers,
39
+ getHashes: _Utils.getHashes
45
40
  };
46
- exports.QuickCrypto = QuickCrypto;
47
41
  //# sourceMappingURL=QuickCrypto.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["QuickCrypto.ts"],"names":["QuickCrypto","createHmac","Hmac","Hash","createHash","createCipher","createCipheriv","createDecipher","createDecipheriv","publicEncrypt","publicDecrypt","privateDecrypt","generateKeyPair","generateKeyPairSync","createSign","createVerify","constants","pbkdf2","random"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAWA;;AACA;;AACA;;AACA;;;;;;AAEO,MAAMA,WAAW,GAAG;AACzBC,EAAAA,UAAU,EAAVA,gBADyB;AAEzBC,EAAAA,IAAI,EAAED,gBAFmB;AAGzBE,EAAAA,IAAI,EAAEC,gBAHmB;AAIzBA,EAAAA,UAAU,EAAVA,gBAJyB;AAKzBC,EAAAA,YAAY,EAAZA,oBALyB;AAMzBC,EAAAA,cAAc,EAAdA,sBANyB;AAOzBC,EAAAA,cAAc,EAAdA,sBAPyB;AAQzBC,EAAAA,gBAAgB,EAAhBA,wBARyB;AASzBC,EAAAA,aAAa,EAAbA,qBATyB;AAUzBC,EAAAA,aAAa,EAAbA,qBAVyB;AAWzBC,EAAAA,cAAc,EAAdA,sBAXyB;AAYzBC,EAAAA,eAAe,EAAfA,uBAZyB;AAazBC,EAAAA,mBAAmB,EAAnBA,2BAbyB;AAczBC,EAAAA,UAAU,EAAVA,eAdyB;AAezBC,EAAAA,YAAY,EAAZA,iBAfyB;AAgBzBC,EAAAA,SAAS,EAATA,oBAhByB;AAiBzB,KAAGC,MAjBsB;AAkBzB,KAAGC;AAlBsB,CAApB","sourcesContent":["import * as pbkdf2 from './pbkdf2';\nimport * as random from './random';\nimport {\n createCipher,\n createCipheriv,\n createDecipher,\n createDecipheriv,\n publicEncrypt,\n publicDecrypt,\n privateDecrypt,\n generateKeyPair,\n generateKeyPairSync,\n} from './Cipher';\nimport { createSign, createVerify } from './sig';\nimport { createHmac } from './Hmac';\nimport { createHash } from './Hash';\nimport { constants } from './constants';\n\nexport const QuickCrypto = {\n createHmac,\n Hmac: createHmac,\n Hash: createHash,\n createHash,\n createCipher,\n createCipheriv,\n createDecipher,\n createDecipheriv,\n publicEncrypt,\n publicDecrypt,\n privateDecrypt,\n generateKeyPair,\n generateKeyPairSync,\n createSign,\n createVerify,\n constants,\n ...pbkdf2,\n ...random,\n};\n"]}
1
+ {"version":3,"names":["pbkdf2","_interopRequireWildcard","require","random","_Cipher","_sig","_Hmac","_Hash","_constants","_subtle","_Utils","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","QuickCrypto","exports","createHmac","Hmac","Hash","createHash","createCipher","createCipheriv","createDecipher","createDecipheriv","publicEncrypt","publicDecrypt","privateDecrypt","generateKeyPair","generateKeyPairSync","createSign","createVerify","subtle","constants","getCiphers","getHashes"],"sourceRoot":"../../src","sources":["QuickCrypto.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAWA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AAAgD,SAAAS,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAX,wBAAAW,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAe,GAAA,CAAAlB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAEzC,MAAMW,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAG;EACzBE,UAAU,EAAVA,gBAAU;EACVC,IAAI,EAAED,gBAAU;EAChBE,IAAI,EAAEC,gBAAU;EAChBA,UAAU,EAAVA,gBAAU;EACVC,YAAY,EAAZA,oBAAY;EACZC,cAAc,EAAdA,sBAAc;EACdC,cAAc,EAAdA,sBAAc;EACdC,gBAAgB,EAAhBA,wBAAgB;EAChBC,aAAa,EAAbA,qBAAa;EACbC,aAAa,EAAbA,qBAAa;EACbC,cAAc,EAAdA,sBAAc;EACdC,eAAe,EAAfA,uBAAe;EACfC,mBAAmB,EAAnBA,2BAAmB;EACnBC,UAAU,EAAVA,eAAU;EACVC,YAAY,EAAZA,iBAAY;EACZC,MAAM,EAANA,cAAM;EACNC,SAAS,EAATA,oBAAS;EACT,GAAGjD,MAAM;EACT,GAAGG,MAAM;EACT+C,UAAU,EAAVA,iBAAU;EACVC,SAAS,EAATA;AACF,CAAC","ignoreList":[]}
@@ -3,33 +3,78 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ setDefaultEncoding: true,
8
+ getDefaultEncoding: true,
9
+ kEmptyObject: true,
10
+ toArrayBuffer: true,
11
+ bufferLikeToArrayBuffer: true,
12
+ binaryLikeToArrayBuffer: true,
13
+ ab2str: true,
14
+ validateString: true,
15
+ validateFunction: true,
16
+ isStringOrBuffer: true,
17
+ validateObject: true,
18
+ validateInt32: true,
19
+ validateUint32: true,
20
+ hasAnyNotIn: true,
21
+ lazyDOMException: true,
22
+ validateMaxBufferLength: true,
23
+ normalizeAlgorithm: true,
24
+ validateBitLength: true,
25
+ validateByteLength: true,
26
+ validateKeyOps: true,
27
+ getHashes: true,
28
+ getCiphers: true
29
+ };
6
30
  exports.ab2str = ab2str;
7
31
  exports.binaryLikeToArrayBuffer = binaryLikeToArrayBuffer;
32
+ exports.bufferLikeToArrayBuffer = bufferLikeToArrayBuffer;
33
+ exports.getCiphers = void 0;
8
34
  exports.getDefaultEncoding = getDefaultEncoding;
35
+ exports.getHashes = void 0;
36
+ exports.hasAnyNotIn = hasAnyNotIn;
9
37
  exports.isStringOrBuffer = isStringOrBuffer;
10
38
  exports.kEmptyObject = void 0;
39
+ exports.lazyDOMException = lazyDOMException;
40
+ exports.normalizeAlgorithm = void 0;
11
41
  exports.setDefaultEncoding = setDefaultEncoding;
12
42
  exports.toArrayBuffer = toArrayBuffer;
43
+ exports.validateByteLength = exports.validateBitLength = void 0;
13
44
  exports.validateFunction = validateFunction;
14
45
  exports.validateInt32 = validateInt32;
46
+ exports.validateMaxBufferLength = exports.validateKeyOps = void 0;
15
47
  exports.validateObject = validateObject;
16
48
  exports.validateString = validateString;
17
49
  exports.validateUint32 = validateUint32;
18
-
19
50
  var _reactNativeBuffer = require("@craftzdog/react-native-buffer");
51
+ var _Hashnames = require("./Hashnames");
52
+ Object.keys(_Hashnames).forEach(function (key) {
53
+ if (key === "default" || key === "__esModule") return;
54
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
55
+ if (key in exports && exports[key] === _Hashnames[key]) return;
56
+ Object.defineProperty(exports, key, {
57
+ enumerable: true,
58
+ get: function () {
59
+ return _Hashnames[key];
60
+ }
61
+ });
62
+ });
63
+ // @types/node
64
+
65
+ // TODO(osp) should buffer be part of the Encoding type?
20
66
 
21
67
  // Mimics node behavior for default global encoding
22
68
  let defaultEncoding = 'buffer';
23
-
24
69
  function setDefaultEncoding(encoding) {
25
70
  defaultEncoding = encoding;
26
71
  }
27
-
28
72
  function getDefaultEncoding() {
29
73
  return defaultEncoding;
30
74
  }
75
+ const kEmptyObject = exports.kEmptyObject = Object.freeze(Object.create(null));
31
76
 
32
- const kEmptyObject = Object.freeze(Object.create(null)); // Should be used by Cipher (or any other module that requires valid encodings)
77
+ // Should be used by Cipher (or any other module that requires valid encodings)
33
78
  // function slowCases(enc: string) {
34
79
  // switch (enc.length) {
35
80
  // case 4:
@@ -91,6 +136,7 @@ const kEmptyObject = Object.freeze(Object.create(null)); // Should be used by Ci
91
136
  // if (enc === '') return 'utf8';
92
137
  // }
93
138
  // }
139
+
94
140
  // // Return undefined if there is no match.
95
141
  // // Move the "slow cases" to a separate function to make sure this function gets
96
142
  // // inlined properly. That prioritizes the common case.
@@ -99,128 +145,408 @@ const kEmptyObject = Object.freeze(Object.create(null)); // Should be used by Ci
99
145
  // return slowCases(enc);
100
146
  // }
101
147
 
102
- exports.kEmptyObject = kEmptyObject;
103
-
104
148
  function toArrayBuffer(buf) {
105
- var _buf$buffer;
106
-
107
- if (buf !== null && buf !== void 0 && (_buf$buffer = buf.buffer) !== null && _buf$buffer !== void 0 && _buf$buffer.slice) {
149
+ if (buf?.buffer?.slice) {
108
150
  return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
109
151
  }
110
-
111
152
  const ab = new ArrayBuffer(buf.length);
112
153
  const view = new Uint8Array(ab);
113
-
114
154
  for (let i = 0; i < buf.length; ++i) {
115
155
  view[i] = buf[i];
116
156
  }
117
-
118
157
  return ab;
119
158
  }
120
-
121
- function binaryLikeToArrayBuffer(input) {
122
- let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf-8';
123
-
159
+ function bufferLikeToArrayBuffer(buf) {
160
+ return _reactNativeBuffer.Buffer.isBuffer(buf) ? buf.buffer : ArrayBuffer.isView(buf) ? buf.buffer : buf;
161
+ }
162
+ function binaryLikeToArrayBuffer(input,
163
+ // CipherKey adds compat with node types
164
+ encoding = 'utf-8') {
124
165
  if (typeof input === 'string') {
166
+ if (encoding === 'buffer') {
167
+ throw new Error('Cannot create a buffer from a string with a buffer encoding');
168
+ }
125
169
  const buffer = _reactNativeBuffer.Buffer.from(input, encoding);
126
-
127
170
  return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
128
171
  }
129
-
130
172
  if (_reactNativeBuffer.Buffer.isBuffer(input)) {
131
173
  return toArrayBuffer(input);
132
- } // TODO add further binary types to BinaryLike, UInt8Array and so for have this array as property
133
-
174
+ }
134
175
 
135
- if (input.buffer) {
176
+ // TODO add further binary types to BinaryLike, UInt8Array and so for have this array as property
177
+ if (ArrayBuffer.isView(input)) {
136
178
  return input.buffer;
137
179
  }
138
-
139
180
  if (!(input instanceof ArrayBuffer)) {
140
181
  try {
182
+ // this is a strange fallback case and input is unknown at this point
183
+ // @ts-expect-error
141
184
  const buffer = _reactNativeBuffer.Buffer.from(input);
142
-
143
185
  return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
144
186
  } catch {
145
187
  throw 'error';
146
188
  }
147
189
  }
148
190
 
191
+ // TODO: handle if input is KeyObject?
192
+
149
193
  return input;
150
194
  }
151
-
152
- function ab2str(buf) {
153
- let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'hex';
195
+ function ab2str(buf, encoding = 'hex') {
154
196
  return _reactNativeBuffer.Buffer.from(buf).toString(encoding);
155
197
  }
156
-
157
198
  function validateString(str, name) {
158
199
  const isString = typeof str === 'string';
159
-
160
- if (isString) {
200
+ if (!isString) {
161
201
  throw new Error(`${name} is not a string`);
162
202
  }
163
-
164
203
  return isString;
165
204
  }
166
-
167
205
  function validateFunction(f) {
168
206
  return f != null && typeof f === 'function';
169
207
  }
170
-
171
208
  function isStringOrBuffer(val) {
172
209
  return typeof val === 'string' || ArrayBuffer.isView(val);
173
210
  }
174
-
175
211
  function validateObject(value, name, options) {
176
212
  const useDefaultOptions = options == null;
177
213
  const allowArray = useDefaultOptions ? false : options.allowArray;
178
214
  const allowFunction = useDefaultOptions ? false : options.allowFunction;
179
215
  const nullable = useDefaultOptions ? false : options.nullable;
180
-
181
216
  if (!nullable && value === null || !allowArray && Array.isArray(value) || typeof value !== 'object' && (!allowFunction || typeof value !== 'function')) {
182
217
  throw new Error(`${name} is not a valid object $${value}`);
183
218
  }
184
-
185
219
  return true;
186
220
  }
187
-
188
- function validateInt32(value, name) {
189
- let min = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -2147483648;
190
- let max = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2147483647;
191
-
221
+ function validateInt32(value, name, min = -2147483648, max = 2147483647) {
192
222
  // The defaults for min and max correspond to the limits of 32-bit integers.
193
223
  if (typeof value !== 'number') {
194
224
  throw new Error(`Invalid argument - ${name} is not a number: ${value}`);
195
225
  }
196
-
197
226
  if (!Number.isInteger(value)) {
198
227
  throw new Error(`Argument out of range - ${name} out of integer range: ${value}`);
199
228
  }
200
-
201
229
  if (value < min || value > max) {
202
230
  throw new Error(`Invalid argument - ${name} out of range >= ${min} && <= ${max}: ${value}`);
203
231
  }
204
232
  }
205
-
206
233
  function validateUint32(value, name, positive) {
207
234
  if (typeof value !== 'number') {
208
235
  // throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
209
236
  throw new Error(`Invalid argument - ${name} is not a number: ${value}`);
210
237
  }
211
-
212
238
  if (!Number.isInteger(value)) {
213
239
  // throw new ERR_OUT_OF_RANGE(name, 'an integer', value);
214
240
  throw new Error(`Argument out of range - ${name} out of integer range: ${value}`);
215
241
  }
216
-
217
- const min = positive ? 1 : 0; // 2 ** 32 === 4294967296
218
-
242
+ const min = positive ? 1 : 0;
243
+ // 2 ** 32 === 4294967296
219
244
  const max = 4294967295;
220
-
221
245
  if (value < min || value > max) {
222
246
  // throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
223
247
  throw new Error(`Invalid argument - ${name} out of range >= ${min} && <= ${max}: ${value}`);
224
248
  }
225
249
  }
250
+ function hasAnyNotIn(set, checks) {
251
+ for (const s of set) {
252
+ if (!checks.includes(s)) {
253
+ return true;
254
+ }
255
+ }
256
+ return false;
257
+ }
258
+ function lazyDOMException(message, domName) {
259
+ let cause = '';
260
+ if (typeof domName !== 'string') {
261
+ cause = `\nCaused by: ${domName.cause}`;
262
+ }
263
+ return new Error(`[${domName}]: ${message}${cause}`);
264
+ }
265
+
266
+ // from lib/internal/crypto/util.js
267
+
268
+ // The maximum buffer size that we'll support in the WebCrypto impl
269
+ const kMaxBufferLength = 2 ** 31 - 1;
270
+
271
+ // // The EC named curves that we currently support via the Web Crypto API.
272
+ // const kNamedCurveAliases = {
273
+ // 'P-256': 'prime256v1',
274
+ // 'P-384': 'secp384r1',
275
+ // 'P-521': 'secp521r1',
276
+ // };
277
+
278
+ // const kAesKeyLengths = [128, 192, 256];
279
+
280
+ // // These are the only hash algorithms we currently support via
281
+ // // the Web Crypto API.
282
+ // const kHashTypes = ['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512'];
283
+
284
+ const kSupportedAlgorithms = {
285
+ 'digest': {
286
+ 'SHA-1': null,
287
+ 'SHA-256': null,
288
+ 'SHA-384': null,
289
+ 'SHA-512': null
290
+ },
291
+ 'generateKey': {
292
+ 'RSASSA-PKCS1-v1_5': 'RsaHashedKeyGenParams',
293
+ 'RSA-PSS': 'RsaHashedKeyGenParams',
294
+ 'RSA-OAEP': 'RsaHashedKeyGenParams',
295
+ 'ECDSA': 'EcKeyGenParams',
296
+ 'ECDH': 'EcKeyGenParams',
297
+ 'AES-CTR': 'AesKeyGenParams',
298
+ 'AES-CBC': 'AesKeyGenParams',
299
+ 'AES-GCM': 'AesKeyGenParams',
300
+ 'AES-KW': 'AesKeyGenParams',
301
+ 'HMAC': 'HmacKeyGenParams',
302
+ 'X25519': null,
303
+ 'Ed25519': null,
304
+ 'X448': null,
305
+ 'Ed448': null
306
+ },
307
+ 'sign': {
308
+ 'RSASSA-PKCS1-v1_5': null,
309
+ 'RSA-PSS': 'RsaPssParams',
310
+ 'ECDSA': 'EcdsaParams',
311
+ 'HMAC': null,
312
+ 'Ed25519': null,
313
+ 'Ed448': 'Ed448Params'
314
+ },
315
+ 'verify': {
316
+ 'RSASSA-PKCS1-v1_5': null,
317
+ 'RSA-PSS': 'RsaPssParams',
318
+ 'ECDSA': 'EcdsaParams',
319
+ 'HMAC': null,
320
+ 'Ed25519': null,
321
+ 'Ed448': 'Ed448Params'
322
+ },
323
+ 'importKey': {
324
+ 'RSASSA-PKCS1-v1_5': 'RsaHashedImportParams',
325
+ 'RSA-PSS': 'RsaHashedImportParams',
326
+ 'RSA-OAEP': 'RsaHashedImportParams',
327
+ 'ECDSA': 'EcKeyImportParams',
328
+ 'ECDH': 'EcKeyImportParams',
329
+ 'HMAC': 'HmacImportParams',
330
+ 'HKDF': null,
331
+ 'PBKDF2': null,
332
+ 'AES-CTR': null,
333
+ 'AES-CBC': null,
334
+ 'AES-GCM': null,
335
+ 'AES-KW': null,
336
+ 'Ed25519': null,
337
+ 'X25519': null,
338
+ 'Ed448': null,
339
+ 'X448': null
340
+ },
341
+ 'deriveBits': {
342
+ HKDF: 'HkdfParams',
343
+ PBKDF2: 'Pbkdf2Params',
344
+ ECDH: 'EcdhKeyDeriveParams',
345
+ X25519: 'EcdhKeyDeriveParams',
346
+ X448: 'EcdhKeyDeriveParams'
347
+ },
348
+ 'encrypt': {
349
+ 'RSA-OAEP': 'RsaOaepParams',
350
+ 'AES-CBC': 'AesCbcParams',
351
+ 'AES-GCM': 'AesGcmParams',
352
+ 'AES-CTR': 'AesCtrParams'
353
+ },
354
+ 'decrypt': {
355
+ 'RSA-OAEP': 'RsaOaepParams',
356
+ 'AES-CBC': 'AesCbcParams',
357
+ 'AES-GCM': 'AesGcmParams',
358
+ 'AES-CTR': 'AesCtrParams'
359
+ },
360
+ 'get key length': {
361
+ 'AES-CBC': 'AesDerivedKeyParams',
362
+ 'AES-CTR': 'AesDerivedKeyParams',
363
+ 'AES-GCM': 'AesDerivedKeyParams',
364
+ 'AES-KW': 'AesDerivedKeyParams',
365
+ 'HMAC': 'HmacImportParams',
366
+ 'HKDF': null,
367
+ 'PBKDF2': null
368
+ },
369
+ 'wrapKey': {
370
+ 'AES-KW': null
371
+ },
372
+ 'unwrapKey': {
373
+ 'AES-KW': null
374
+ }
375
+ };
376
+
377
+ // const simpleAlgorithmDictionaries = {
378
+ // AesGcmParams: { iv: 'BufferSource', additionalData: 'BufferSource' },
379
+ // RsaHashedKeyGenParams: { hash: 'HashAlgorithmIdentifier' },
380
+ // EcKeyGenParams: {},
381
+ // HmacKeyGenParams: { hash: 'HashAlgorithmIdentifier' },
382
+ // RsaPssParams: {},
383
+ // EcdsaParams: { hash: 'HashAlgorithmIdentifier' },
384
+ // HmacImportParams: { hash: 'HashAlgorithmIdentifier' },
385
+ // HkdfParams: {
386
+ // hash: 'HashAlgorithmIdentifier',
387
+ // salt: 'BufferSource',
388
+ // info: 'BufferSource',
389
+ // },
390
+ // Ed448Params: { context: 'BufferSource' },
391
+ // Pbkdf2Params: { hash: 'HashAlgorithmIdentifier', salt: 'BufferSource' },
392
+ // RsaOaepParams: { label: 'BufferSource' },
393
+ // RsaHashedImportParams: { hash: 'HashAlgorithmIdentifier' },
394
+ // EcKeyImportParams: {},
395
+ // };
396
+
397
+ const validateMaxBufferLength = (data, name) => {
398
+ const length = typeof data === 'string' ? data.length : data.byteLength;
399
+ if (length > kMaxBufferLength) {
400
+ throw lazyDOMException(`${name} must be less than ${kMaxBufferLength + 1} bits`, 'OperationError');
401
+ }
402
+ };
403
+
404
+ // https://w3c.github.io/webcrypto/#algorithm-normalization-normalize-an-algorithm
405
+ // adapted for Node.js from Deno's implementation
406
+ // https://github.com/denoland/deno/blob/v1.29.1/ext/crypto/00_crypto.js#L195
407
+ exports.validateMaxBufferLength = validateMaxBufferLength;
408
+ const normalizeAlgorithm = (algorithm, op) => {
409
+ if (typeof algorithm === 'string') return normalizeAlgorithm({
410
+ name: algorithm
411
+ }, op);
412
+
413
+ // 1.
414
+ const registeredAlgorithms = kSupportedAlgorithms[op];
415
+ // 2. 3.
416
+ // commented, because typescript takes care of this for us 🤞👀
417
+ // const initialAlg = webidl.converters.Algorithm(algorithm, {
418
+ // prefix: 'Failed to normalize algorithm',
419
+ // context: 'passed algorithm',
420
+ // });
421
+
422
+ // 4.
423
+ let algName = algorithm.name;
424
+
425
+ // 5.
426
+ let desiredType;
427
+ for (const key in registeredAlgorithms) {
428
+ if (!registeredAlgorithms.hasOwnProperty(key)) {
429
+ continue;
430
+ }
431
+ if (key.toUpperCase() === algName.toUpperCase()) {
432
+ algName = key;
433
+ // @ts-ignore
434
+ desiredType = registeredAlgorithms[algName];
435
+ }
436
+ }
437
+ if (desiredType === undefined) throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
438
+
439
+ // Fast path everything below if the registered dictionary is null
440
+ if (desiredType === null) return {
441
+ name: algName
442
+ };
443
+ throw lazyDOMException(`normalizeAlgorithm() not implemented for ${op} / ${algName} / ${desiredType}`, 'NotSupportedError');
444
+ // TODO: implement these below when needed
445
+
446
+ // // 8.
447
+ // const normalizedAlgorithm = webidl.converters[desiredType](algorithm, {
448
+ // prefix: 'Failed to normalize algorithm',
449
+ // context: 'passed algorithm',
450
+ // });
451
+ // // 9.
452
+ // normalizedAlgorithm.name = algName;
453
+
454
+ // // 9.
455
+ // const dict = simpleAlgorithmDictionaries[desiredType];
456
+ // // 10.
457
+ // const dictKeys = dict ? Object.keys(dict) : [];
458
+ // for (let i = 0; i < dictKeys.length; i++) {
459
+ // const member = dictKeys[i];
460
+ // if (!dict.hasOwnProperty(member)) continue;
461
+ // const idlType = dict[member];
462
+ // const idlValue = normalizedAlgorithm[member];
463
+ // // 3.
464
+ // if (idlType === 'BufferSource' && idlValue) {
465
+ // const isView = ArrayBufferIsView(idlValue);
466
+ // normalizedAlgorithm[member] = TypedArrayPrototypeSlice(
467
+ // new Uint8Array(
468
+ // isView ? getDataViewOrTypedArrayBuffer(idlValue) : idlValue,
469
+ // isView ? getDataViewOrTypedArrayByteOffset(idlValue) : 0,
470
+ // isView
471
+ // ? getDataViewOrTypedArrayByteLength(idlValue)
472
+ // : ArrayBufferPrototypeGetByteLength(idlValue)
473
+ // )
474
+ // );
475
+ // } else if (idlType === 'HashAlgorithmIdentifier') {
476
+ // normalizedAlgorithm[member] = normalizeAlgorithm(idlValue, 'digest');
477
+ // } else if (idlType === 'AlgorithmIdentifier') {
478
+ // // This extension point is not used by any supported algorithm (yet?)
479
+ // throw lazyDOMException('Not implemented.', 'NotSupportedError');
480
+ // }
481
+ // }
482
+
483
+ // return normalizedAlgorithm;
484
+ };
485
+ exports.normalizeAlgorithm = normalizeAlgorithm;
486
+ const validateBitLength = (length, name, required = false) => {
487
+ if (length !== undefined || required) {
488
+ // validateNumber(length, name);
489
+ if (length < 0) throw new Error(`${name} > 0`);
490
+ if (length % 8) {
491
+ throw lazyDOMException(`${name}'s length (${length}) must be a multiple of 8`, 'InvalidArgument');
492
+ }
493
+ }
494
+ };
495
+ exports.validateBitLength = validateBitLength;
496
+ const validateByteLength = (buf, name, target) => {
497
+ if (buf.byteLength !== target) {
498
+ throw lazyDOMException(`${name} must contain exactly ${target} bytes`, 'OperationError');
499
+ }
500
+ };
501
+ exports.validateByteLength = validateByteLength;
502
+ const kKeyOps = {
503
+ sign: 1,
504
+ verify: 2,
505
+ encrypt: 3,
506
+ decrypt: 4,
507
+ wrapKey: 5,
508
+ unwrapKey: 6,
509
+ deriveKey: 7,
510
+ deriveBits: 8
511
+ };
512
+ const validateKeyOps = (keyOps, usagesSet) => {
513
+ if (keyOps === undefined) return;
514
+ if (!Array.isArray(keyOps)) {
515
+ throw lazyDOMException('keyData.key_ops', 'InvalidArgument');
516
+ }
517
+ let flags = 0;
518
+ for (let n = 0; n < keyOps.length; n++) {
519
+ const op = keyOps[n];
520
+ const op_flag = kKeyOps[op];
521
+ // Skipping unknown key ops
522
+ if (op_flag === undefined) continue;
523
+ // Have we seen it already? if so, error
524
+ // eslint-disable-next-line no-bitwise
525
+ if (flags & 1 << op_flag) throw lazyDOMException('Duplicate key operation', 'DataError');
526
+ // eslint-disable-next-line no-bitwise
527
+ flags |= 1 << op_flag;
528
+
529
+ // TODO(@jasnell): RFC7517 section 4.3 strong recommends validating
530
+ // key usage combinations. Specifically, it says that unrelated key
531
+ // ops SHOULD NOT be used together. We're not yet validating that here.
532
+ }
533
+ if (usagesSet !== undefined) {
534
+ for (const use of usagesSet) {
535
+ if (!keyOps.includes(use)) {
536
+ throw lazyDOMException('Key operations and usage mismatch', 'DataError');
537
+ }
538
+ }
539
+ }
540
+ };
541
+
542
+ // TODO: these used to be shipped by crypto-browserify in quickcrypto v0.6
543
+ // could instead fetch from OpenSSL if needed and handle breaking changes
544
+ exports.validateKeyOps = validateKeyOps;
545
+ const getHashes = () => ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160', 'sha224WithRSAEncryption', 'RSA-SHA224', 'sha256WithRSAEncryption', 'RSA-SHA256', 'sha384WithRSAEncryption', 'RSA-SHA384', 'sha512WithRSAEncryption', 'RSA-SHA512', 'RSA-SHA1', 'ecdsa-with-SHA1', 'sha256', 'sha224', 'sha384', 'sha512', 'DSA-SHA', 'DSA-SHA1', 'DSA', 'DSA-WITH-SHA224', 'DSA-SHA224', 'DSA-WITH-SHA256', 'DSA-SHA256', 'DSA-WITH-SHA384', 'DSA-SHA384', 'DSA-WITH-SHA512', 'DSA-SHA512', 'DSA-RIPEMD160', 'ripemd160WithRSA', 'RSA-RIPEMD160', 'md5WithRSAEncryption', 'RSA-MD5'];
546
+
547
+ // TODO: these used to be shipped by crypto-browserify in quickcrypto v0.6
548
+ // could instead fetch from OpenSSL if needed and handle breaking changes
549
+ exports.getHashes = getHashes;
550
+ const getCiphers = () => ['des-ecb', 'des', 'des-cbc', 'des3', 'des-ede3-cbc', 'des-ede3', 'des-ede-cbc', 'des-ede', 'aes-128-ecb', 'aes-192-ecb', 'aes-256-ecb', 'aes-128-cbc', 'aes-192-cbc', 'aes-256-cbc', 'aes128', 'aes192', 'aes256', 'aes-128-cfb', 'aes-192-cfb', 'aes-256-cfb', 'aes-128-cfb8', 'aes-192-cfb8', 'aes-256-cfb8', 'aes-128-cfb1', 'aes-192-cfb1', 'aes-256-cfb1', 'aes-128-ofb', 'aes-192-ofb', 'aes-256-ofb', 'aes-128-ctr', 'aes-192-ctr', 'aes-256-ctr', 'aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm'];
551
+ exports.getCiphers = getCiphers;
226
552
  //# sourceMappingURL=Utils.js.map