expo-crypto 10.2.0 → 12.0.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,6 +10,22 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 12.0.0 — 2022-10-25
14
+
15
+ ### 🛠 Breaking changes
16
+
17
+ - Bumped iOS deployment target to 13.0 and deprecated support for iOS 12. ([#18873](https://github.com/expo/expo/pull/18873) by [@tsapeta](https://github.com/tsapeta))
18
+
19
+ ## 11.0.0 — 2022-07-07
20
+
21
+ ### 🎉 New features
22
+
23
+ - The module on Android now uses JSI host object instead of the bridge module for communication between JavaScript and native code. ([#17614](https://github.com/expo/expo/pull/17614) by [@lukmccall](https://github.com/lukmccall))
24
+
25
+ ### 💡 Others
26
+
27
+ - Migrated Expo modules definitions to the new naming convention. ([#17193](https://github.com/expo/expo/pull/17193) by [@tsapeta](https://github.com/tsapeta))
28
+
13
29
  ## 10.2.0 — 2022-04-18
14
30
 
15
31
  ### 🎉 New features
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '10.2.0'
6
+ version = '12.0.0'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -74,7 +74,7 @@ android {
74
74
  minSdkVersion safeExtGet("minSdkVersion", 21)
75
75
  targetSdkVersion safeExtGet("targetSdkVersion", 31)
76
76
  versionCode 25
77
- versionName "10.2.0"
77
+ versionName "12.0.0"
78
78
  }
79
79
  lintOptions {
80
80
  abortOnError false
@@ -1,45 +1,32 @@
1
1
  package expo.modules.crypto
2
2
 
3
- import android.content.Context
4
3
  import android.util.Base64
5
-
6
- import expo.modules.core.ExportedModule
7
- import expo.modules.core.Promise
8
- import expo.modules.core.interfaces.ExpoMethod
9
-
4
+ import expo.modules.kotlin.modules.Module
5
+ import expo.modules.kotlin.modules.ModuleDefinition
10
6
  import java.security.MessageDigest
11
- import java.security.NoSuchAlgorithmException
12
7
 
13
- class CryptoModule(context: Context) : ExportedModule(context) {
14
- override fun getName() = "ExpoCrypto"
8
+ class CryptoModule : Module() {
9
+ override fun definition() = ModuleDefinition {
10
+ Name("ExpoCrypto")
15
11
 
16
- @ExpoMethod
17
- fun digestStringAsync(algorithm: String, data: String, options: Map<String, Any?>, promise: Promise) {
18
- val encoding = options["encoding"] as String?
12
+ Function("digestString", this@CryptoModule::digestString)
13
+ AsyncFunction("digestStringAsync", this@CryptoModule::digestString)
14
+ }
19
15
 
20
- val messageDigest = try {
21
- MessageDigest.getInstance(algorithm).apply { update(data.toByteArray()) }
22
- } catch (e: NoSuchAlgorithmException) {
23
- promise.reject("ERR_CRYPTO_DIGEST", e)
24
- return
25
- }
16
+ private fun digestString(algorithm: DigestAlgorithm, data: String, options: DigestOptions): String {
17
+ val messageDigest = MessageDigest.getInstance(algorithm.value).apply { update(data.toByteArray()) }
26
18
 
27
19
  val digest: ByteArray = messageDigest.digest()
28
- when (encoding) {
29
- "base64" -> {
30
- val output = Base64.encodeToString(digest, Base64.NO_WRAP)
31
- promise.resolve(output)
20
+ return when (options.encoding) {
21
+ DigestOptions.Encoding.BASE64 -> {
22
+ Base64.encodeToString(digest, Base64.NO_WRAP)
32
23
  }
33
- "hex" -> {
34
- val output = digest.joinToString(separator = "") { byte ->
24
+ DigestOptions.Encoding.HEX -> {
25
+ digest.joinToString(separator = "") { byte ->
35
26
  ((byte.toInt() and 0xff) + 0x100)
36
27
  .toString(radix = 16)
37
28
  .substring(startIndex = 1)
38
29
  }
39
- promise.resolve(output)
40
- }
41
- else -> {
42
- promise.reject("ERR_CRYPTO_DIGEST", "Invalid encoding type provided.")
43
30
  }
44
31
  }
45
32
  }
@@ -0,0 +1,11 @@
1
+ package expo.modules.crypto
2
+
3
+ import expo.modules.kotlin.types.Enumerable
4
+
5
+ enum class DigestAlgorithm(val value: String) : Enumerable {
6
+ MD5("MD5"),
7
+ SHA1("SHA-1"),
8
+ SHA256("SHA-256"),
9
+ SHA384("SHA-384"),
10
+ SHA512("SHA-512")
11
+ }
@@ -0,0 +1,15 @@
1
+ package expo.modules.crypto
2
+
3
+ import expo.modules.kotlin.records.Field
4
+ import expo.modules.kotlin.records.Record
5
+ import expo.modules.kotlin.types.Enumerable
6
+
7
+ class DigestOptions : Record {
8
+ @Field
9
+ var encoding: Encoding = Encoding.HEX
10
+
11
+ enum class Encoding(val value: String) : Enumerable {
12
+ HEX("hex"),
13
+ BASE64("base64")
14
+ }
15
+ }
@@ -1,6 +1,10 @@
1
1
  {
2
+ "name": "expo-crypto",
2
3
  "platforms": ["ios", "android"],
3
4
  "ios": {
4
5
  "modulesClassNames": ["CryptoModule"]
6
+ },
7
+ "android": {
8
+ "modulesClassNames": ["expo.modules.crypto.CryptoModule"]
5
9
  }
6
10
  }
@@ -5,12 +5,11 @@ import ExpoModulesCore
5
5
 
6
6
  public class CryptoModule: Module {
7
7
  public func definition() -> ModuleDefinition {
8
- name("ExpoCrypto")
8
+ Name("ExpoCrypto")
9
9
 
10
- function("digestStringAsync", digestString)
10
+ AsyncFunction("digestStringAsync", digestString)
11
11
 
12
- function("digestString", digestString)
13
- .runSynchronously()
12
+ Function("digestString", digestString)
14
13
  }
15
14
  }
16
15
 
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
10
10
  s.license = package['license']
11
11
  s.author = package['author']
12
12
  s.homepage = package['homepage']
13
- s.platform = :ios, '12.0'
13
+ s.platform = :ios, '13.0'
14
14
  s.swift_version = '5.4'
15
15
  s.source = { git: 'https://github.com/expo/expo.git' }
16
16
  s.static_framework = true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-crypto",
3
- "version": "10.2.0",
3
+ "version": "12.0.0",
4
4
  "description": "Expo universal module for crypto",
5
5
  "main": "build/Crypto.js",
6
6
  "types": "build/Crypto.d.ts",
@@ -40,10 +40,10 @@
40
40
  },
41
41
  "dependencies": {},
42
42
  "devDependencies": {
43
- "expo-module-scripts": "^2.0.0"
43
+ "expo-module-scripts": "^3.0.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "expo": "*"
47
47
  },
48
- "gitHead": "89a27c0ca0ca8becd7546697298e874a15e94faf"
48
+ "gitHead": "eab2b09c735fb0fc2bf734a3f29a6593adba3838"
49
49
  }
package/tsconfig.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "outDir": "./build"
6
6
  },
7
7
  "include": ["./src"],
8
- "exclude": ["**/__mocks__/*", "**/__tests__/*"]
8
+ "exclude": ["**/__mocks__/*", "**/__tests__/*", "**/__stories__/*"]
9
9
  }
@@ -1,9 +0,0 @@
1
- package expo.modules.crypto
2
-
3
- import android.content.Context
4
- import expo.modules.core.BasePackage
5
- import expo.modules.core.ExportedModule
6
-
7
- class CryptoPackage : BasePackage() {
8
- override fun createExportedModules(context: Context): List<ExportedModule> = listOf(CryptoModule(context))
9
- }