expo-crypto 10.1.1 → 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 +27 -0
- package/README.md +3 -3
- package/android/build.gradle +43 -26
- package/android/src/main/java/expo/modules/crypto/CryptoModule.kt +15 -28
- package/android/src/main/java/expo/modules/crypto/DigestAlgorithm.kt +9 -0
- package/android/src/main/java/expo/modules/crypto/DigestOptions.kt +14 -0
- package/build/Crypto.d.ts +1 -0
- package/build/Crypto.d.ts.map +1 -0
- package/build/Crypto.types.d.ts +1 -4
- package/build/Crypto.types.d.ts.map +1 -0
- package/build/Crypto.types.js +0 -4
- package/build/Crypto.types.js.map +1 -1
- package/build/ExpoCrypto.d.ts +2 -1
- package/build/ExpoCrypto.d.ts.map +1 -0
- package/build/ExpoCrypto.js +2 -2
- package/build/ExpoCrypto.js.map +1 -1
- package/build/ExpoCrypto.web.d.ts +1 -0
- package/build/ExpoCrypto.web.d.ts.map +1 -0
- package/expo-module.config.json +10 -0
- package/ios/CryptoModule.swift +40 -0
- package/ios/DigestAlgorithm.swift +63 -0
- package/ios/DigestOptions.swift +13 -0
- package/ios/{EXCrypto.podspec → ExpoCrypto.podspec} +10 -3
- package/package.json +2 -2
- package/src/Crypto.types.ts +0 -4
- package/src/ExpoCrypto.ts +3 -2
- package/tsconfig.json +1 -1
- package/android/src/main/java/expo/modules/crypto/CryptoPackage.kt +0 -9
- package/ios/EXCrypto/EXCrypto.h +0 -7
- package/ios/EXCrypto/EXCrypto.m +0 -84
- package/unimodule.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,33 @@
|
|
|
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
|
+
|
|
23
|
+
## 10.2.0 — 2022-04-18
|
|
24
|
+
|
|
25
|
+
### 🎉 New features
|
|
26
|
+
|
|
27
|
+
- 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))
|
|
28
|
+
- 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))
|
|
29
|
+
|
|
30
|
+
### ⚠️ Notices
|
|
31
|
+
|
|
32
|
+
- 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))
|
|
33
|
+
|
|
34
|
+
## 10.1.2 - 2022-02-01
|
|
35
|
+
|
|
36
|
+
### 🐛 Bug fixes
|
|
37
|
+
|
|
38
|
+
- Fix `Plugin with id 'maven' not found` build error from Android Gradle 7. ([#16080](https://github.com/expo/expo/pull/16080) by [@kudo](https://github.com/kudo))
|
|
39
|
+
|
|
13
40
|
## 10.1.1 — 2021-12-08
|
|
14
41
|
|
|
15
42
|
_This version does not introduce any user-facing changes._
|
package/README.md
CHANGED
|
@@ -4,12 +4,12 @@ Provides cryptography primitives.
|
|
|
4
4
|
|
|
5
5
|
# API documentation
|
|
6
6
|
|
|
7
|
-
- [Documentation for the
|
|
8
|
-
- [Documentation for the latest stable release](https://docs.expo.
|
|
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
|
|
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
|
|
package/android/build.gradle
CHANGED
|
@@ -1,63 +1,80 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
2
|
apply plugin: 'kotlin-android'
|
|
3
|
-
apply plugin: 'maven'
|
|
3
|
+
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '
|
|
6
|
+
version = '11.0.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:${
|
|
34
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
|
|
20
35
|
}
|
|
21
36
|
}
|
|
22
37
|
|
|
23
|
-
// Upload android library to maven with javadoc and android sources
|
|
24
|
-
configurations {
|
|
25
|
-
deployerJars
|
|
26
|
-
}
|
|
27
|
-
|
|
28
38
|
// Creating sources with comments
|
|
29
39
|
task androidSourcesJar(type: Jar) {
|
|
30
40
|
classifier = 'sources'
|
|
31
41
|
from android.sourceSets.main.java.srcDirs
|
|
32
42
|
}
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
afterEvaluate {
|
|
45
|
+
publishing {
|
|
46
|
+
publications {
|
|
47
|
+
release(MavenPublication) {
|
|
48
|
+
from components.release
|
|
49
|
+
// Add additional sourcesJar to artifacts
|
|
50
|
+
artifact(androidSourcesJar)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
repositories {
|
|
54
|
+
maven {
|
|
55
|
+
url = mavenLocal().url
|
|
56
|
+
}
|
|
44
57
|
}
|
|
45
58
|
}
|
|
46
59
|
}
|
|
47
60
|
|
|
48
61
|
android {
|
|
49
|
-
compileSdkVersion safeExtGet("compileSdkVersion",
|
|
62
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 31)
|
|
50
63
|
|
|
51
64
|
compileOptions {
|
|
52
|
-
sourceCompatibility JavaVersion.
|
|
53
|
-
targetCompatibility JavaVersion.
|
|
65
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
66
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
kotlinOptions {
|
|
70
|
+
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
54
71
|
}
|
|
55
72
|
|
|
56
73
|
defaultConfig {
|
|
57
74
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
58
|
-
targetSdkVersion safeExtGet("targetSdkVersion",
|
|
75
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 31)
|
|
59
76
|
versionCode 25
|
|
60
|
-
versionName "
|
|
77
|
+
versionName "11.0.0"
|
|
61
78
|
}
|
|
62
79
|
lintOptions {
|
|
63
80
|
abortOnError false
|
|
@@ -67,10 +84,10 @@ android {
|
|
|
67
84
|
dependencies {
|
|
68
85
|
implementation project(':expo-modules-core')
|
|
69
86
|
|
|
70
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${
|
|
87
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
71
88
|
|
|
72
|
-
if (project.findProject(':
|
|
73
|
-
testImplementation project(':
|
|
89
|
+
if (project.findProject(':expo-modules-test-core')) {
|
|
90
|
+
testImplementation project(':expo-modules-test-core')
|
|
74
91
|
}
|
|
75
92
|
testImplementation 'junit:junit:4.12'
|
|
76
93
|
testImplementation "org.robolectric:robolectric:4.3.1"
|
|
@@ -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.
|
|
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
|
|
14
|
-
override fun
|
|
8
|
+
class CryptoModule : Module() {
|
|
9
|
+
override fun definition() = ModuleDefinition {
|
|
10
|
+
Name("ExpoCrypto")
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
Function("digestString", this@CryptoModule::digestString)
|
|
13
|
+
AsyncFunction("digestStringAsync", this@CryptoModule::digestString)
|
|
14
|
+
}
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
promise.resolve(output)
|
|
20
|
+
return when (options.encoding) {
|
|
21
|
+
DigestOptions.Encoding.BASE64 -> {
|
|
22
|
+
Base64.encodeToString(digest, Base64.NO_WRAP)
|
|
32
23
|
}
|
|
33
|
-
|
|
34
|
-
|
|
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,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
|
+
}
|
package/build/Crypto.d.ts
CHANGED
|
@@ -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"}
|
package/build/Crypto.types.d.ts
CHANGED
|
@@ -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"}
|
package/build/Crypto.types.js
CHANGED
|
@@ -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
|
|
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"]}
|
package/build/ExpoCrypto.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoCrypto.d.ts","sourceRoot":"","sources":["../src/ExpoCrypto.ts"],"names":[],"mappings":";AAEA,wBAAiD"}
|
package/build/ExpoCrypto.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default
|
|
1
|
+
import { requireNativeModule } from 'expo-modules-core';
|
|
2
|
+
export default requireNativeModule('ExpoCrypto');
|
|
3
3
|
//# sourceMappingURL=ExpoCrypto.js.map
|
package/build/ExpoCrypto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoCrypto.js","sourceRoot":"","sources":["../src/ExpoCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
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"]}
|
|
@@ -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,40 @@
|
|
|
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
|
+
AsyncFunction("digestStringAsync", digestString)
|
|
11
|
+
|
|
12
|
+
Function("digestString", digestString)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private func digestString(algorithm: DigestAlgorithm, str: String, options: DigestOptions) throws -> String {
|
|
17
|
+
guard let data = str.data(using: .utf8) else {
|
|
18
|
+
throw LossyConversionException()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let length = Int(algorithm.digestLength)
|
|
22
|
+
var digest = [UInt8](repeating: 0, count: length)
|
|
23
|
+
|
|
24
|
+
data.withUnsafeBytes { bytes in
|
|
25
|
+
let _ = algorithm.digest(bytes.baseAddress, UInt32(data.count), &digest)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
switch options.encoding {
|
|
29
|
+
case .hex:
|
|
30
|
+
return digest.reduce("") { $0 + String(format: "%02x", $1) }
|
|
31
|
+
case .base64:
|
|
32
|
+
return Data(digest).base64EncodedString()
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private class LossyConversionException: Exception {
|
|
37
|
+
override var reason: String {
|
|
38
|
+
"Unable to convert given string without losing some information"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -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 = '
|
|
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 = "
|
|
27
|
+
s.source_files = "**/*.h"
|
|
21
28
|
s.vendored_frameworks = "#{s.name}.xcframework"
|
|
22
29
|
else
|
|
23
|
-
s.source_files = "
|
|
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": "
|
|
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": "
|
|
48
|
+
"gitHead": "e893ff2b01e108cf246cec02318c0df9d6bc603c"
|
|
49
49
|
}
|
package/src/Crypto.types.ts
CHANGED
|
@@ -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 {
|
|
2
|
-
|
|
1
|
+
import { requireNativeModule } from 'expo-modules-core';
|
|
2
|
+
|
|
3
|
+
export default requireNativeModule('ExpoCrypto');
|
package/tsconfig.json
CHANGED
|
@@ -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
|
-
}
|
package/ios/EXCrypto/EXCrypto.h
DELETED
package/ios/EXCrypto/EXCrypto.m
DELETED
|
@@ -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