expo-crypto 10.2.0 → 11.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,16 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 11.0.0 — 2022-07-07
14
+
15
+ ### 🎉 New features
16
+
17
+ - 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))
18
+
19
+ ### 💡 Others
20
+
21
+ - Migrated Expo modules definitions to the new naming convention. ([#17193](https://github.com/expo/expo/pull/17193) by [@tsapeta](https://github.com/tsapeta))
22
+
13
23
  ## 10.2.0 — 2022-04-18
14
24
 
15
25
  ### 🎉 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 = '11.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 "11.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,9 @@
1
+ package expo.modules.crypto
2
+
3
+ enum class DigestAlgorithm(val value: String) {
4
+ MD5("MD5"),
5
+ SHA1("SHA-1"),
6
+ SHA256("SHA-256"),
7
+ SHA384("SHA-384"),
8
+ SHA512("SHA-512")
9
+ }
@@ -0,0 +1,14 @@
1
+ package expo.modules.crypto
2
+
3
+ import expo.modules.kotlin.records.Field
4
+ import expo.modules.kotlin.records.Record
5
+
6
+ class DigestOptions : Record {
7
+ @Field
8
+ var encoding: Encoding = Encoding.HEX
9
+
10
+ enum class Encoding(val value: String) {
11
+ HEX("hex"),
12
+ BASE64("base64")
13
+ }
14
+ }
@@ -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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-crypto",
3
- "version": "10.2.0",
3
+ "version": "11.0.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": "89a27c0ca0ca8becd7546697298e874a15e94faf"
48
+ "gitHead": "e893ff2b01e108cf246cec02318c0df9d6bc603c"
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
- }