expo-crypto 10.1.2 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,7 +10,18 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 10.1.2 — 2022-02-01
13
+ ## 10.2.0 — 2022-04-18
14
+
15
+ ### 🎉 New features
16
+
17
+ - Native module on iOS is now written in Swift using the new API. ([#16129](https://github.com/expo/expo/pull/16129) by [@tsapeta](https://github.com/tsapeta))
18
+ - Use JSI host object instead of the bridge module for communication between JavaScript and native code. ([#16972](https://github.com/expo/expo/pull/16972) by [@tsapeta](https://github.com/tsapeta))
19
+
20
+ ### ⚠️ Notices
21
+
22
+ - On Android bump `compileSdkVersion` to `31`, `targetSdkVersion` to `31` and `Java` version to `11`. ([#16941](https://github.com/expo/expo/pull/16941) by [@bbarthec](https://github.com/bbarthec))
23
+
24
+ ## 10.1.2 - 2022-02-01
14
25
 
15
26
  ### 🐛 Bug fixes
16
27
 
package/README.md CHANGED
@@ -4,12 +4,12 @@ Provides cryptography primitives.
4
4
 
5
5
  # API documentation
6
6
 
7
- - [Documentation for the master branch](https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/sdk/crypto.md)
8
- - [Documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/crypto/)
7
+ - [Documentation for the main branch](https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/crypto.md)
8
+ - [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/crypto/)
9
9
 
10
10
  # Installation in managed Expo projects
11
11
 
12
- For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/crypto/).
12
+ For [managed](https://docs.expo.dev/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/crypto/).
13
13
 
14
14
  # Installation in bare React Native projects
15
15
 
@@ -3,20 +3,35 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '10.1.2'
6
+ version = '10.2.0'
7
7
 
8
8
  buildscript {
9
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
10
+ if (expoModulesCorePlugin.exists()) {
11
+ apply from: expoModulesCorePlugin
12
+ applyKotlinExpoModulesCorePlugin()
13
+ }
14
+
9
15
  // Simple helper that allows the root project to override versions declared by this library.
10
16
  ext.safeExtGet = { prop, fallback ->
11
17
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
12
18
  }
13
19
 
20
+ // Ensures backward compatibility
21
+ ext.getKotlinVersion = {
22
+ if (ext.has("kotlinVersion")) {
23
+ ext.kotlinVersion()
24
+ } else {
25
+ ext.safeExtGet("kotlinVersion", "1.6.10")
26
+ }
27
+ }
28
+
14
29
  repositories {
15
30
  mavenCentral()
16
31
  }
17
32
 
18
33
  dependencies {
19
- classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.4.21')}")
34
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
20
35
  }
21
36
  }
22
37
 
@@ -44,18 +59,22 @@ afterEvaluate {
44
59
  }
45
60
 
46
61
  android {
47
- compileSdkVersion safeExtGet("compileSdkVersion", 30)
62
+ compileSdkVersion safeExtGet("compileSdkVersion", 31)
48
63
 
49
64
  compileOptions {
50
- sourceCompatibility JavaVersion.VERSION_1_8
51
- targetCompatibility JavaVersion.VERSION_1_8
65
+ sourceCompatibility JavaVersion.VERSION_11
66
+ targetCompatibility JavaVersion.VERSION_11
67
+ }
68
+
69
+ kotlinOptions {
70
+ jvmTarget = JavaVersion.VERSION_11.majorVersion
52
71
  }
53
72
 
54
73
  defaultConfig {
55
74
  minSdkVersion safeExtGet("minSdkVersion", 21)
56
- targetSdkVersion safeExtGet("targetSdkVersion", 30)
75
+ targetSdkVersion safeExtGet("targetSdkVersion", 31)
57
76
  versionCode 25
58
- versionName "10.1.2"
77
+ versionName "10.2.0"
59
78
  }
60
79
  lintOptions {
61
80
  abortOnError false
@@ -65,10 +84,10 @@ android {
65
84
  dependencies {
66
85
  implementation project(':expo-modules-core')
67
86
 
68
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.4.21')}"
87
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
69
88
 
70
- if (project.findProject(':unimodules-test-core')) {
71
- testImplementation project(':unimodules-test-core')
89
+ if (project.findProject(':expo-modules-test-core')) {
90
+ testImplementation project(':expo-modules-test-core')
72
91
  }
73
92
  testImplementation 'junit:junit:4.12'
74
93
  testImplementation "org.robolectric:robolectric:4.3.1"
package/build/Crypto.d.ts CHANGED
@@ -21,3 +21,4 @@ export * from './Crypto.types';
21
21
  * ```
22
22
  */
23
23
  export declare function digestStringAsync(algorithm: CryptoDigestAlgorithm, data: string, options?: CryptoDigestOptions): Promise<Digest>;
24
+ //# sourceMappingURL=Crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../src/Crypto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAkB,mBAAmB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGpG,cAAc,gBAAgB,CAAC;AAqC/B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,qBAAqB,EAChC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,mBAAsD,GAC9D,OAAO,CAAC,MAAM,CAAC,CAUjB"}
@@ -1,9 +1,5 @@
1
1
  /**
2
2
  * [`Cryptographic hash function`](https://developer.mozilla.org/en-US/docs/Glossary/Cryptographic_hash_function)
3
- * is an algorithm that can be used to generate a checksum value. They have a variety of applications in cryptography.
4
- * > Cryptographic hash functions like [`SHA1`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#SHA-1),
5
- * > `MD5` are **vulnerable**! Attacks have been proven to significantly reduce their collision resistance.
6
- * > Message-digest algorithms shouldn't be used for creating secure digests.
7
3
  */
8
4
  export declare enum CryptoDigestAlgorithm {
9
5
  /**
@@ -53,3 +49,4 @@ export declare type CryptoDigestOptions = {
53
49
  encoding: CryptoEncoding;
54
50
  };
55
51
  export declare type Digest = string;
52
+ //# sourceMappingURL=Crypto.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Crypto.types.d.ts","sourceRoot":"","sources":["../src/Crypto.types.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,oBAAY,qBAAqB;IAC/B;;OAEG;IACH,IAAI,UAAU;IACd;;OAEG;IACH,MAAM,YAAY;IAClB;;OAEG;IACH,MAAM,YAAY;IAClB;;OAEG;IACH,MAAM,YAAY;IAClB;;;OAGG;IACH,GAAG,QAAQ;IACX;;;OAGG;IACH,GAAG,QAAQ;IACX;;;;OAIG;IACH,GAAG,QAAQ;CACZ;AAGD,oBAAY,cAAc;IACxB,GAAG,QAAQ;IACX;;OAEG;IACH,MAAM,WAAW;CAClB;AAGD,oBAAY,mBAAmB,GAAG;IAChC;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AAGF,oBAAY,MAAM,GAAG,MAAM,CAAC"}
@@ -1,10 +1,6 @@
1
1
  // @needsAudit
2
2
  /**
3
3
  * [`Cryptographic hash function`](https://developer.mozilla.org/en-US/docs/Glossary/Cryptographic_hash_function)
4
- * is an algorithm that can be used to generate a checksum value. They have a variety of applications in cryptography.
5
- * > Cryptographic hash functions like [`SHA1`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#SHA-1),
6
- * > `MD5` are **vulnerable**! Attacks have been proven to significantly reduce their collision resistance.
7
- * > Message-digest algorithms shouldn't be used for creating secure digests.
8
4
  */
9
5
  export var CryptoDigestAlgorithm;
10
6
  (function (CryptoDigestAlgorithm) {
@@ -1 +1 @@
1
- {"version":3,"file":"Crypto.types.js","sourceRoot":"","sources":["../src/Crypto.types.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,qBAiCX;AAjCD,WAAY,qBAAqB;IAC/B;;OAEG;IACH,uCAAc,CAAA;IACd;;OAEG;IACH,2CAAkB,CAAA;IAClB;;OAEG;IACH,2CAAkB,CAAA;IAClB;;OAEG;IACH,2CAAkB,CAAA;IAClB;;;OAGG;IACH,oCAAW,CAAA;IACX;;;OAGG;IACH,oCAAW,CAAA;IACX;;;;OAIG;IACH,oCAAW,CAAA;AACb,CAAC,EAjCW,qBAAqB,KAArB,qBAAqB,QAiChC;AAED,cAAc;AACd,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,6BAAW,CAAA;IACX;;OAEG;IACH,mCAAiB,CAAA;AACnB,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB","sourcesContent":["// @needsAudit\n/**\n * [`Cryptographic hash function`](https://developer.mozilla.org/en-US/docs/Glossary/Cryptographic_hash_function)\n * is an algorithm that can be used to generate a checksum value. They have a variety of applications in cryptography.\n * > Cryptographic hash functions like [`SHA1`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#SHA-1),\n * > `MD5` are **vulnerable**! Attacks have been proven to significantly reduce their collision resistance.\n * > Message-digest algorithms shouldn't be used for creating secure digests.\n */\nexport enum CryptoDigestAlgorithm {\n /**\n * `160` bits.\n */\n SHA1 = 'SHA-1',\n /**\n * `256` bits. Collision Resistant.\n */\n SHA256 = 'SHA-256',\n /**\n * `384` bits. Collision Resistant.\n */\n SHA384 = 'SHA-384',\n /**\n * `512` bits. Collision Resistant.\n */\n SHA512 = 'SHA-512',\n /**\n * `128` bits.\n * @platform ios\n */\n MD2 = 'MD2',\n /**\n * `128` bits.\n * @platform ios\n */\n MD4 = 'MD4',\n /**\n * `128` bits.\n * @platform android\n * @platform ios\n */\n MD5 = 'MD5',\n}\n\n// @needsAudit\nexport enum CryptoEncoding {\n HEX = 'hex',\n /**\n * Has trailing padding. Does not wrap lines. Does not have a trailing newline.\n */\n BASE64 = 'base64',\n}\n\n// @needsAudit\nexport type CryptoDigestOptions = {\n /**\n * Format the digest is returned in.\n */\n encoding: CryptoEncoding;\n};\n\n// @docsMissing\nexport type Digest = string;\n"]}
1
+ {"version":3,"file":"Crypto.types.js","sourceRoot":"","sources":["../src/Crypto.types.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;GAEG;AACH,MAAM,CAAN,IAAY,qBAiCX;AAjCD,WAAY,qBAAqB;IAC/B;;OAEG;IACH,uCAAc,CAAA;IACd;;OAEG;IACH,2CAAkB,CAAA;IAClB;;OAEG;IACH,2CAAkB,CAAA;IAClB;;OAEG;IACH,2CAAkB,CAAA;IAClB;;;OAGG;IACH,oCAAW,CAAA;IACX;;;OAGG;IACH,oCAAW,CAAA;IACX;;;;OAIG;IACH,oCAAW,CAAA;AACb,CAAC,EAjCW,qBAAqB,KAArB,qBAAqB,QAiChC;AAED,cAAc;AACd,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,6BAAW,CAAA;IACX;;OAEG;IACH,mCAAiB,CAAA;AACnB,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB","sourcesContent":["// @needsAudit\n/**\n * [`Cryptographic hash function`](https://developer.mozilla.org/en-US/docs/Glossary/Cryptographic_hash_function)\n */\nexport enum CryptoDigestAlgorithm {\n /**\n * `160` bits.\n */\n SHA1 = 'SHA-1',\n /**\n * `256` bits. Collision Resistant.\n */\n SHA256 = 'SHA-256',\n /**\n * `384` bits. Collision Resistant.\n */\n SHA384 = 'SHA-384',\n /**\n * `512` bits. Collision Resistant.\n */\n SHA512 = 'SHA-512',\n /**\n * `128` bits.\n * @platform ios\n */\n MD2 = 'MD2',\n /**\n * `128` bits.\n * @platform ios\n */\n MD4 = 'MD4',\n /**\n * `128` bits.\n * @platform android\n * @platform ios\n */\n MD5 = 'MD5',\n}\n\n// @needsAudit\nexport enum CryptoEncoding {\n HEX = 'hex',\n /**\n * Has trailing padding. Does not wrap lines. Does not have a trailing newline.\n */\n BASE64 = 'base64',\n}\n\n// @needsAudit\nexport type CryptoDigestOptions = {\n /**\n * Format the digest is returned in.\n */\n encoding: CryptoEncoding;\n};\n\n// @docsMissing\nexport type Digest = string;\n"]}
@@ -1,2 +1,3 @@
1
- declare const _default: import("expo-modules-core").ProxyNativeModule;
1
+ declare const _default: any;
2
2
  export default _default;
3
+ //# sourceMappingURL=ExpoCrypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoCrypto.d.ts","sourceRoot":"","sources":["../src/ExpoCrypto.ts"],"names":[],"mappings":";AAEA,wBAAiD"}
@@ -1,3 +1,3 @@
1
- import { NativeModulesProxy } from 'expo-modules-core';
2
- export default NativeModulesProxy.ExpoCrypto;
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+ export default requireNativeModule('ExpoCrypto');
3
3
  //# sourceMappingURL=ExpoCrypto.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoCrypto.js","sourceRoot":"","sources":["../src/ExpoCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,eAAe,kBAAkB,CAAC,UAAU,CAAC","sourcesContent":["import { NativeModulesProxy } from 'expo-modules-core';\nexport default NativeModulesProxy.ExpoCrypto;\n"]}
1
+ {"version":3,"file":"ExpoCrypto.js","sourceRoot":"","sources":["../src/ExpoCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,eAAe,mBAAmB,CAAC,YAAY,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\n\nexport default requireNativeModule('ExpoCrypto');\n"]}
@@ -4,3 +4,4 @@ declare const _default: {
4
4
  digestStringAsync(algorithm: CryptoDigestAlgorithm, data: string, options: CryptoDigestOptions): Promise<string>;
5
5
  };
6
6
  export default _default;
7
+ //# sourceMappingURL=ExpoCrypto.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoCrypto.web.d.ts","sourceRoot":"","sources":["../src/ExpoCrypto.web.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAkB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;;;iCAO7E,qBAAqB,QAC1B,MAAM,WACH,mBAAmB,GAC3B,QAAQ,MAAM,CAAC;;AARpB,wBAyBE"}
@@ -0,0 +1,6 @@
1
+ {
2
+ "platforms": ["ios", "android"],
3
+ "ios": {
4
+ "modulesClassNames": ["CryptoModule"]
5
+ }
6
+ }
@@ -0,0 +1,41 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ import CommonCrypto
4
+ import ExpoModulesCore
5
+
6
+ public class CryptoModule: Module {
7
+ public func definition() -> ModuleDefinition {
8
+ name("ExpoCrypto")
9
+
10
+ function("digestStringAsync", digestString)
11
+
12
+ function("digestString", digestString)
13
+ .runSynchronously()
14
+ }
15
+ }
16
+
17
+ private func digestString(algorithm: DigestAlgorithm, str: String, options: DigestOptions) throws -> String {
18
+ guard let data = str.data(using: .utf8) else {
19
+ throw LossyConversionException()
20
+ }
21
+
22
+ let length = Int(algorithm.digestLength)
23
+ var digest = [UInt8](repeating: 0, count: length)
24
+
25
+ data.withUnsafeBytes { bytes in
26
+ let _ = algorithm.digest(bytes.baseAddress, UInt32(data.count), &digest)
27
+ }
28
+
29
+ switch options.encoding {
30
+ case .hex:
31
+ return digest.reduce("") { $0 + String(format: "%02x", $1) }
32
+ case .base64:
33
+ return Data(digest).base64EncodedString()
34
+ }
35
+ }
36
+
37
+ private class LossyConversionException: Exception {
38
+ override var reason: String {
39
+ "Unable to convert given string without losing some information"
40
+ }
41
+ }
@@ -0,0 +1,63 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ import CommonCrypto
4
+ import ExpoModulesCore
5
+
6
+ typealias DigestFunction = (
7
+ _ data: UnsafeRawPointer?,
8
+ _ len: UInt32,
9
+ _ md: UnsafeMutablePointer<UInt8>?
10
+ ) -> UnsafeMutablePointer<UInt8>?
11
+
12
+ internal enum DigestAlgorithm: String, EnumArgument {
13
+ case md2 = "MD2"
14
+ case md4 = "MD4"
15
+ case md5 = "MD5"
16
+ case sha1 = "SHA-1"
17
+ case sha224 = "SHA-224"
18
+ case sha256 = "SHA-256"
19
+ case sha384 = "SHA-384"
20
+ case sha512 = "SHA-512"
21
+
22
+ var digestLength: Int32 {
23
+ switch self {
24
+ case .md2:
25
+ return CC_MD2_DIGEST_LENGTH
26
+ case .md4:
27
+ return CC_MD4_DIGEST_LENGTH
28
+ case .md5:
29
+ return CC_MD5_DIGEST_LENGTH
30
+ case .sha1:
31
+ return CC_SHA1_DIGEST_LENGTH
32
+ case .sha224:
33
+ return CC_SHA224_DIGEST_LENGTH
34
+ case .sha256:
35
+ return CC_SHA256_DIGEST_LENGTH
36
+ case .sha384:
37
+ return CC_SHA384_DIGEST_LENGTH
38
+ case .sha512:
39
+ return CC_SHA512_DIGEST_LENGTH
40
+ }
41
+ }
42
+
43
+ var digest: DigestFunction {
44
+ switch self {
45
+ case .md2:
46
+ return CC_MD2
47
+ case .md4:
48
+ return CC_MD4
49
+ case .md5:
50
+ return CC_MD5
51
+ case .sha1:
52
+ return CC_SHA1
53
+ case .sha224:
54
+ return CC_SHA224
55
+ case .sha256:
56
+ return CC_SHA256
57
+ case .sha384:
58
+ return CC_SHA384
59
+ case .sha512:
60
+ return CC_SHA512
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesCore
4
+
5
+ internal struct DigestOptions: Record {
6
+ @Field
7
+ var encoding: Encoding = .hex
8
+
9
+ internal enum Encoding: String, EnumArgument {
10
+ case hex = "hex"
11
+ case base64 = "base64"
12
+ }
13
+ }
@@ -3,7 +3,7 @@ require 'json'
3
3
  package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
4
4
 
5
5
  Pod::Spec.new do |s|
6
- s.name = 'EXCrypto'
6
+ s.name = 'ExpoCrypto'
7
7
  s.version = package['version']
8
8
  s.summary = package['description']
9
9
  s.description = package['description']
@@ -11,15 +11,22 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.homepage = package['homepage']
13
13
  s.platform = :ios, '12.0'
14
+ s.swift_version = '5.4'
14
15
  s.source = { git: 'https://github.com/expo/expo.git' }
15
16
  s.static_framework = true
16
17
 
17
18
  s.dependency 'ExpoModulesCore'
18
19
 
20
+ # Swift/Objective-C compatibility
21
+ s.pod_target_xcconfig = {
22
+ 'DEFINES_MODULE' => 'YES',
23
+ 'SWIFT_COMPILATION_MODE' => 'wholemodule'
24
+ }
25
+
19
26
  if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
20
- s.source_files = "#{s.name}/**/*.h"
27
+ s.source_files = "**/*.h"
21
28
  s.vendored_frameworks = "#{s.name}.xcframework"
22
29
  else
23
- s.source_files = "#{s.name}/**/*.{h,m}"
30
+ s.source_files = "**/*.{h,m,swift}"
24
31
  end
25
32
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-crypto",
3
- "version": "10.1.2",
3
+ "version": "10.2.0",
4
4
  "description": "Expo universal module for crypto",
5
5
  "main": "build/Crypto.js",
6
6
  "types": "build/Crypto.d.ts",
@@ -45,5 +45,5 @@
45
45
  "peerDependencies": {
46
46
  "expo": "*"
47
47
  },
48
- "gitHead": "ba24eba18bf4f4d4b0d54828992d81a2bb18246a"
48
+ "gitHead": "89a27c0ca0ca8becd7546697298e874a15e94faf"
49
49
  }
@@ -1,10 +1,6 @@
1
1
  // @needsAudit
2
2
  /**
3
3
  * [`Cryptographic hash function`](https://developer.mozilla.org/en-US/docs/Glossary/Cryptographic_hash_function)
4
- * is an algorithm that can be used to generate a checksum value. They have a variety of applications in cryptography.
5
- * > Cryptographic hash functions like [`SHA1`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#SHA-1),
6
- * > `MD5` are **vulnerable**! Attacks have been proven to significantly reduce their collision resistance.
7
- * > Message-digest algorithms shouldn't be used for creating secure digests.
8
4
  */
9
5
  export enum CryptoDigestAlgorithm {
10
6
  /**
package/src/ExpoCrypto.ts CHANGED
@@ -1,2 +1,3 @@
1
- import { NativeModulesProxy } from 'expo-modules-core';
2
- export default NativeModulesProxy.ExpoCrypto;
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+
3
+ export default requireNativeModule('ExpoCrypto');
@@ -1,7 +0,0 @@
1
- // Copyright 2019-present 650 Industries. All rights reserved.
2
-
3
- #import <ExpoModulesCore/EXExportedModule.h>
4
-
5
- @interface EXCrypto : EXExportedModule
6
-
7
- @end
@@ -1,84 +0,0 @@
1
- // Copyright 2019-present 650 Industries. All rights reserved.
2
-
3
- #import <EXCrypto/EXCrypto.h>
4
- #import <CommonCrypto/CommonDigest.h>
5
-
6
- @implementation EXCrypto
7
-
8
- EX_EXPORT_MODULE(ExpoCrypto);
9
-
10
- EX_EXPORT_METHOD_AS(digestStringAsync,
11
- digestStringAsync:(NSString *)algorithm
12
- data:(NSString *)data
13
- options:(NSDictionary *)options
14
- resolver:(EXPromiseResolveBlock)resolve
15
- rejecter:(EXPromiseRejectBlock)reject)
16
- {
17
- NSString *encoding = options[@"encoding"];
18
-
19
- int digestLength = [EXCrypto digestLengthForJSAlgorithm:algorithm];
20
- if (digestLength == -1) {
21
- reject(@"ERR_CRYPTO_DIGEST", [NSString stringWithFormat:@"Invalid hashing algorithm: %@", algorithm], nil);
22
- return;
23
- }
24
-
25
- NSData *_data = [data dataUsingEncoding:NSUTF8StringEncoding];
26
- uint8_t digest[digestLength];
27
- if ([algorithm isEqualToString:@"MD2"]) {
28
- CC_MD2(_data.bytes, (CC_LONG)_data.length, digest);
29
- } else if ([algorithm isEqualToString:@"MD4"]) {
30
- CC_MD4(_data.bytes, (CC_LONG)_data.length, digest);
31
- } else if ([algorithm isEqualToString:@"MD5"]) {
32
- CC_MD5(_data.bytes, (CC_LONG)_data.length, digest);
33
- } else if ([algorithm isEqualToString:@"SHA-1"]) {
34
- CC_SHA1(_data.bytes, (CC_LONG)_data.length, digest);
35
- } else if ([algorithm isEqualToString:@"SHA-224"]) {
36
- CC_SHA224(_data.bytes, (CC_LONG)_data.length, digest);
37
- } else if ([algorithm isEqualToString:@"SHA-256"]) {
38
- CC_SHA256(_data.bytes, (CC_LONG)_data.length, digest);
39
- } else if ([algorithm isEqualToString:@"SHA-384"]) {
40
- CC_SHA384(_data.bytes, (CC_LONG)_data.length, digest);
41
- } else if ([algorithm isEqualToString:@"SHA-512"]) {
42
- CC_SHA512(_data.bytes, (CC_LONG)_data.length, digest);
43
- }
44
-
45
- if ([encoding isEqualToString:@"hex"]) {
46
- NSMutableString *output = [NSMutableString stringWithCapacity:digestLength * 2];
47
- for (int i = 0; i < digestLength; i++) {
48
- [output appendFormat:@"%02x", digest[i]];
49
- }
50
- resolve(output);
51
- return;
52
- } else if ([encoding isEqualToString:@"base64"]) {
53
- NSData *originalData = [NSData dataWithBytes:digest length:digestLength];
54
- NSString *output = [originalData base64EncodedStringWithOptions:0];
55
- resolve(output);
56
- return;
57
- } else {
58
- reject(@"ERR_CRYPTO_DIGEST", @"Invalid encoding type provided.", nil);
59
- return;
60
- }
61
- }
62
-
63
- + (int)digestLengthForJSAlgorithm:(NSString *)input {
64
- if ([input isEqualToString:@"MD2"]) {
65
- return CC_MD2_DIGEST_LENGTH;
66
- } else if ([input isEqualToString:@"MD4"]) {
67
- return CC_MD4_DIGEST_LENGTH;
68
- } else if ([input isEqualToString:@"MD5"]) {
69
- return CC_MD5_DIGEST_LENGTH;
70
- } else if ([input isEqualToString:@"SHA-1"]) {
71
- return CC_SHA1_DIGEST_LENGTH;
72
- } else if ([input isEqualToString:@"SHA-224"]) {
73
- return CC_SHA224_DIGEST_LENGTH;
74
- } else if ([input isEqualToString:@"SHA-256"]) {
75
- return CC_SHA256_DIGEST_LENGTH;
76
- } else if ([input isEqualToString:@"SHA-384"]) {
77
- return CC_SHA384_DIGEST_LENGTH;
78
- } else if ([input isEqualToString:@"SHA-512"]) {
79
- return CC_SHA512_DIGEST_LENGTH;
80
- }
81
- return -1;
82
- }
83
-
84
- @end
package/unimodule.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "name": "expo-crypto",
3
- "platforms": ["ios", "android"]
4
- }