expo-crypto 10.1.0 → 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 +21 -0
- package/README.md +3 -3
- package/android/build.gradle +43 -26
- package/build/Crypto.d.ts +21 -0
- package/build/Crypto.d.ts.map +1 -0
- package/build/Crypto.js +21 -0
- package/build/Crypto.js.map +1 -1
- package/build/Crypto.types.d.ts +31 -4
- package/build/Crypto.types.d.ts.map +1 -0
- package/build/Crypto.types.js +29 -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 +6 -0
- package/ios/CryptoModule.swift +41 -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.ts +21 -0
- package/src/Crypto.types.ts +37 -5
- package/src/ExpoCrypto.ts +3 -2
- 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,27 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
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
|
|
25
|
+
|
|
26
|
+
### 🐛 Bug fixes
|
|
27
|
+
|
|
28
|
+
- 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))
|
|
29
|
+
|
|
30
|
+
## 10.1.1 — 2021-12-08
|
|
31
|
+
|
|
32
|
+
_This version does not introduce any user-facing changes._
|
|
33
|
+
|
|
13
34
|
## 10.1.0 — 2021-12-03
|
|
14
35
|
|
|
15
36
|
_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 = '10.
|
|
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:${
|
|
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 "10.
|
|
77
|
+
versionName "10.2.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"
|
package/build/Crypto.d.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
1
|
import { CryptoDigestAlgorithm, CryptoDigestOptions, Digest } from './Crypto.types';
|
|
2
2
|
export * from './Crypto.types';
|
|
3
|
+
/**
|
|
4
|
+
* The `digestStringAsync()` method of `Crypto` generates a digest of the supplied `data` string with the provided digest `algorithm`.
|
|
5
|
+
* A digest is a short fixed-length value derived from some variable-length input. **Cryptographic digests** should exhibit _collision-resistance_,
|
|
6
|
+
* meaning that it's very difficult to generate multiple inputs that have equal digest values.
|
|
7
|
+
* You can specify the returned string format as one of `CryptoEncoding`. By default, the resolved value will be formatted as a `HEX` string.
|
|
8
|
+
* On web, this method can only be called from a secure origin (https) otherwise an error will be thrown.
|
|
9
|
+
*
|
|
10
|
+
* @param algorithm The cryptographic hash function to use to transform a block of data into a fixed-size output.
|
|
11
|
+
* @param data The value that will be used to generate a digest.
|
|
12
|
+
* @param options Format of the digest string. Defaults to: `CryptoDigestOptions.HEX`.
|
|
13
|
+
* @return Return a Promise which fulfills with a value representing the hashed input.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const digest = await Crypto.digestStringAsync(
|
|
18
|
+
* Crypto.CryptoDigestAlgorithm.SHA512,
|
|
19
|
+
* '🥓 Easy to Digest! 💙'
|
|
20
|
+
* );
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
3
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"}
|
package/build/Crypto.js
CHANGED
|
@@ -23,6 +23,27 @@ function assertEncoding(encoding) {
|
|
|
23
23
|
throw new CryptoError(`Invalid encoding provided. Expected one of: CryptoEncoding.${Object.keys(CryptoEncoding).join(', CryptoEncoding.')}`);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
// @needsAudit
|
|
27
|
+
/**
|
|
28
|
+
* The `digestStringAsync()` method of `Crypto` generates a digest of the supplied `data` string with the provided digest `algorithm`.
|
|
29
|
+
* A digest is a short fixed-length value derived from some variable-length input. **Cryptographic digests** should exhibit _collision-resistance_,
|
|
30
|
+
* meaning that it's very difficult to generate multiple inputs that have equal digest values.
|
|
31
|
+
* You can specify the returned string format as one of `CryptoEncoding`. By default, the resolved value will be formatted as a `HEX` string.
|
|
32
|
+
* On web, this method can only be called from a secure origin (https) otherwise an error will be thrown.
|
|
33
|
+
*
|
|
34
|
+
* @param algorithm The cryptographic hash function to use to transform a block of data into a fixed-size output.
|
|
35
|
+
* @param data The value that will be used to generate a digest.
|
|
36
|
+
* @param options Format of the digest string. Defaults to: `CryptoDigestOptions.HEX`.
|
|
37
|
+
* @return Return a Promise which fulfills with a value representing the hashed input.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const digest = await Crypto.digestStringAsync(
|
|
42
|
+
* Crypto.CryptoDigestAlgorithm.SHA512,
|
|
43
|
+
* '🥓 Easy to Digest! 💙'
|
|
44
|
+
* );
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
26
47
|
export async function digestStringAsync(algorithm, data, options = { encoding: CryptoEncoding.HEX }) {
|
|
27
48
|
if (!ExpoCrypto.digestStringAsync) {
|
|
28
49
|
throw new UnavailabilityError('expo-crypto', 'digestStringAsync');
|
package/build/Crypto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Crypto.js","sourceRoot":"","sources":["../src/Crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAA+B,MAAM,gBAAgB,CAAC;AACpG,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,cAAc,gBAAgB,CAAC;AAE/B,MAAM,WAAY,SAAQ,SAAS;IACjC,IAAI,GAAG,YAAY,CAAC;IAEpB,YAAY,OAAe;QACzB,KAAK,CAAC,gBAAgB,OAAO,EAAE,CAAC,CAAC;IACnC,CAAC;CACF;AAED,SAAS,eAAe,CAAC,SAAgC;IACvD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;QAC7D,MAAM,IAAI,WAAW,CACnB,sEAAsE,MAAM,CAAC,IAAI,CAC/E,qBAAqB,CACtB,CAAC,IAAI,CAAC,mCAAmC,CAAC,EAAE,CAC9C,CAAC;KACH;AACH,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAI,WAAW,CAAC,2CAA2C,CAAC,CAAC;KACpE;AACH,CAAC;AAED,SAAS,cAAc,CAAC,QAAwB;IAC9C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACrD,MAAM,IAAI,WAAW,CACnB,8DAA8D,MAAM,CAAC,IAAI,CACvE,cAAc,CACf,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAC9B,CAAC;KACH;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,SAAgC,EAChC,IAAY,EACZ,UAA+B,EAAE,QAAQ,EAAE,cAAc,CAAC,GAAG,EAAE;IAE/D,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE;QACjC,MAAM,IAAI,mBAAmB,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC;KACnE;IAED,eAAe,CAAC,SAAS,CAAC,CAAC;IAC3B,UAAU,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEjC,OAAO,MAAM,UAAU,CAAC,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\n\nimport { CryptoDigestAlgorithm, CryptoEncoding, CryptoDigestOptions, Digest } from './Crypto.types';\nimport ExpoCrypto from './ExpoCrypto';\n\nexport * from './Crypto.types';\n\nclass CryptoError extends TypeError {\n code = 'ERR_CRYPTO';\n\n constructor(message: string) {\n super(`expo-crypto: ${message}`);\n }\n}\n\nfunction assertAlgorithm(algorithm: CryptoDigestAlgorithm): void {\n if (!Object.values(CryptoDigestAlgorithm).includes(algorithm)) {\n throw new CryptoError(\n `Invalid algorithm provided. Expected one of: CryptoDigestAlgorithm.${Object.keys(\n CryptoDigestAlgorithm\n ).join(', AlgCryptoDigestAlgorithmorithm.')}`\n );\n }\n}\n\nfunction assertData(data: string): void {\n if (typeof data !== 'string') {\n throw new CryptoError(`Invalid data provided. Expected a string.`);\n }\n}\n\nfunction assertEncoding(encoding: CryptoEncoding): void {\n if (!Object.values(CryptoEncoding).includes(encoding)) {\n throw new CryptoError(\n `Invalid encoding provided. Expected one of: CryptoEncoding.${Object.keys(\n CryptoEncoding\n ).join(', CryptoEncoding.')}`\n );\n }\n}\n\nexport async function digestStringAsync(\n algorithm: CryptoDigestAlgorithm,\n data: string,\n options: CryptoDigestOptions = { encoding: CryptoEncoding.HEX }\n): Promise<Digest> {\n if (!ExpoCrypto.digestStringAsync) {\n throw new UnavailabilityError('expo-crypto', 'digestStringAsync');\n }\n\n assertAlgorithm(algorithm);\n assertData(data);\n assertEncoding(options.encoding);\n\n return await ExpoCrypto.digestStringAsync(algorithm, data, options);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Crypto.js","sourceRoot":"","sources":["../src/Crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAA+B,MAAM,gBAAgB,CAAC;AACpG,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,cAAc,gBAAgB,CAAC;AAE/B,MAAM,WAAY,SAAQ,SAAS;IACjC,IAAI,GAAG,YAAY,CAAC;IAEpB,YAAY,OAAe;QACzB,KAAK,CAAC,gBAAgB,OAAO,EAAE,CAAC,CAAC;IACnC,CAAC;CACF;AAED,SAAS,eAAe,CAAC,SAAgC;IACvD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;QAC7D,MAAM,IAAI,WAAW,CACnB,sEAAsE,MAAM,CAAC,IAAI,CAC/E,qBAAqB,CACtB,CAAC,IAAI,CAAC,mCAAmC,CAAC,EAAE,CAC9C,CAAC;KACH;AACH,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAI,WAAW,CAAC,2CAA2C,CAAC,CAAC;KACpE;AACH,CAAC;AAED,SAAS,cAAc,CAAC,QAAwB;IAC9C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACrD,MAAM,IAAI,WAAW,CACnB,8DAA8D,MAAM,CAAC,IAAI,CACvE,cAAc,CACf,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAC9B,CAAC;KACH;AACH,CAAC;AAED,cAAc;AACd;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,SAAgC,EAChC,IAAY,EACZ,UAA+B,EAAE,QAAQ,EAAE,cAAc,CAAC,GAAG,EAAE;IAE/D,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE;QACjC,MAAM,IAAI,mBAAmB,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC;KACnE;IAED,eAAe,CAAC,SAAS,CAAC,CAAC;IAC3B,UAAU,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEjC,OAAO,MAAM,UAAU,CAAC,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\n\nimport { CryptoDigestAlgorithm, CryptoEncoding, CryptoDigestOptions, Digest } from './Crypto.types';\nimport ExpoCrypto from './ExpoCrypto';\n\nexport * from './Crypto.types';\n\nclass CryptoError extends TypeError {\n code = 'ERR_CRYPTO';\n\n constructor(message: string) {\n super(`expo-crypto: ${message}`);\n }\n}\n\nfunction assertAlgorithm(algorithm: CryptoDigestAlgorithm): void {\n if (!Object.values(CryptoDigestAlgorithm).includes(algorithm)) {\n throw new CryptoError(\n `Invalid algorithm provided. Expected one of: CryptoDigestAlgorithm.${Object.keys(\n CryptoDigestAlgorithm\n ).join(', AlgCryptoDigestAlgorithmorithm.')}`\n );\n }\n}\n\nfunction assertData(data: string): void {\n if (typeof data !== 'string') {\n throw new CryptoError(`Invalid data provided. Expected a string.`);\n }\n}\n\nfunction assertEncoding(encoding: CryptoEncoding): void {\n if (!Object.values(CryptoEncoding).includes(encoding)) {\n throw new CryptoError(\n `Invalid encoding provided. Expected one of: CryptoEncoding.${Object.keys(\n CryptoEncoding\n ).join(', CryptoEncoding.')}`\n );\n }\n}\n\n// @needsAudit\n/**\n * The `digestStringAsync()` method of `Crypto` generates a digest of the supplied `data` string with the provided digest `algorithm`.\n * A digest is a short fixed-length value derived from some variable-length input. **Cryptographic digests** should exhibit _collision-resistance_,\n * meaning that it's very difficult to generate multiple inputs that have equal digest values.\n * You can specify the returned string format as one of `CryptoEncoding`. By default, the resolved value will be formatted as a `HEX` string.\n * On web, this method can only be called from a secure origin (https) otherwise an error will be thrown.\n *\n * @param algorithm The cryptographic hash function to use to transform a block of data into a fixed-size output.\n * @param data The value that will be used to generate a digest.\n * @param options Format of the digest string. Defaults to: `CryptoDigestOptions.HEX`.\n * @return Return a Promise which fulfills with a value representing the hashed input.\n *\n * @example\n * ```ts\n * const digest = await Crypto.digestStringAsync(\n * Crypto.CryptoDigestAlgorithm.SHA512,\n * '🥓 Easy to Digest! 💙'\n * );\n * ```\n */\nexport async function digestStringAsync(\n algorithm: CryptoDigestAlgorithm,\n data: string,\n options: CryptoDigestOptions = { encoding: CryptoEncoding.HEX }\n): Promise<Digest> {\n if (!ExpoCrypto.digestStringAsync) {\n throw new UnavailabilityError('expo-crypto', 'digestStringAsync');\n }\n\n assertAlgorithm(algorithm);\n assertData(data);\n assertEncoding(options.encoding);\n\n return await ExpoCrypto.digestStringAsync(algorithm, data, options);\n}\n"]}
|
package/build/Crypto.types.d.ts
CHANGED
|
@@ -1,25 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [`Cryptographic hash function`](https://developer.mozilla.org/en-US/docs/Glossary/Cryptographic_hash_function)
|
|
3
|
+
*/
|
|
1
4
|
export declare enum CryptoDigestAlgorithm {
|
|
2
5
|
/**
|
|
3
|
-
*
|
|
4
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#SHA-1
|
|
6
|
+
* `160` bits.
|
|
5
7
|
*/
|
|
6
8
|
SHA1 = "SHA-1",
|
|
9
|
+
/**
|
|
10
|
+
* `256` bits. Collision Resistant.
|
|
11
|
+
*/
|
|
7
12
|
SHA256 = "SHA-256",
|
|
13
|
+
/**
|
|
14
|
+
* `384` bits. Collision Resistant.
|
|
15
|
+
*/
|
|
8
16
|
SHA384 = "SHA-384",
|
|
17
|
+
/**
|
|
18
|
+
* `512` bits. Collision Resistant.
|
|
19
|
+
*/
|
|
9
20
|
SHA512 = "SHA-512",
|
|
10
21
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
22
|
+
* `128` bits.
|
|
23
|
+
* @platform ios
|
|
13
24
|
*/
|
|
14
25
|
MD2 = "MD2",
|
|
26
|
+
/**
|
|
27
|
+
* `128` bits.
|
|
28
|
+
* @platform ios
|
|
29
|
+
*/
|
|
15
30
|
MD4 = "MD4",
|
|
31
|
+
/**
|
|
32
|
+
* `128` bits.
|
|
33
|
+
* @platform android
|
|
34
|
+
* @platform ios
|
|
35
|
+
*/
|
|
16
36
|
MD5 = "MD5"
|
|
17
37
|
}
|
|
18
38
|
export declare enum CryptoEncoding {
|
|
19
39
|
HEX = "hex",
|
|
40
|
+
/**
|
|
41
|
+
* Has trailing padding. Does not wrap lines. Does not have a trailing newline.
|
|
42
|
+
*/
|
|
20
43
|
BASE64 = "base64"
|
|
21
44
|
}
|
|
22
45
|
export declare type CryptoDigestOptions = {
|
|
46
|
+
/**
|
|
47
|
+
* Format the digest is returned in.
|
|
48
|
+
*/
|
|
23
49
|
encoding: CryptoEncoding;
|
|
24
50
|
};
|
|
25
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,24 +1,49 @@
|
|
|
1
|
+
// @needsAudit
|
|
2
|
+
/**
|
|
3
|
+
* [`Cryptographic hash function`](https://developer.mozilla.org/en-US/docs/Glossary/Cryptographic_hash_function)
|
|
4
|
+
*/
|
|
1
5
|
export var CryptoDigestAlgorithm;
|
|
2
6
|
(function (CryptoDigestAlgorithm) {
|
|
3
7
|
/**
|
|
4
|
-
*
|
|
5
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#SHA-1
|
|
8
|
+
* `160` bits.
|
|
6
9
|
*/
|
|
7
10
|
CryptoDigestAlgorithm["SHA1"] = "SHA-1";
|
|
11
|
+
/**
|
|
12
|
+
* `256` bits. Collision Resistant.
|
|
13
|
+
*/
|
|
8
14
|
CryptoDigestAlgorithm["SHA256"] = "SHA-256";
|
|
15
|
+
/**
|
|
16
|
+
* `384` bits. Collision Resistant.
|
|
17
|
+
*/
|
|
9
18
|
CryptoDigestAlgorithm["SHA384"] = "SHA-384";
|
|
19
|
+
/**
|
|
20
|
+
* `512` bits. Collision Resistant.
|
|
21
|
+
*/
|
|
10
22
|
CryptoDigestAlgorithm["SHA512"] = "SHA-512";
|
|
11
23
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
24
|
+
* `128` bits.
|
|
25
|
+
* @platform ios
|
|
14
26
|
*/
|
|
15
27
|
CryptoDigestAlgorithm["MD2"] = "MD2";
|
|
28
|
+
/**
|
|
29
|
+
* `128` bits.
|
|
30
|
+
* @platform ios
|
|
31
|
+
*/
|
|
16
32
|
CryptoDigestAlgorithm["MD4"] = "MD4";
|
|
33
|
+
/**
|
|
34
|
+
* `128` bits.
|
|
35
|
+
* @platform android
|
|
36
|
+
* @platform ios
|
|
37
|
+
*/
|
|
17
38
|
CryptoDigestAlgorithm["MD5"] = "MD5";
|
|
18
39
|
})(CryptoDigestAlgorithm || (CryptoDigestAlgorithm = {}));
|
|
40
|
+
// @needsAudit
|
|
19
41
|
export var CryptoEncoding;
|
|
20
42
|
(function (CryptoEncoding) {
|
|
21
43
|
CryptoEncoding["HEX"] = "hex";
|
|
44
|
+
/**
|
|
45
|
+
* Has trailing padding. Does not wrap lines. Does not have a trailing newline.
|
|
46
|
+
*/
|
|
22
47
|
CryptoEncoding["BASE64"] = "base64";
|
|
23
48
|
})(CryptoEncoding || (CryptoEncoding = {}));
|
|
24
49
|
//# sourceMappingURL=Crypto.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Crypto.types.js","sourceRoot":"","sources":["../src/Crypto.types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,
|
|
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,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 = '
|
|
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": "10.
|
|
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": "
|
|
48
|
+
"gitHead": "89a27c0ca0ca8becd7546697298e874a15e94faf"
|
|
49
49
|
}
|
package/src/Crypto.ts
CHANGED
|
@@ -39,6 +39,27 @@ function assertEncoding(encoding: CryptoEncoding): void {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// @needsAudit
|
|
43
|
+
/**
|
|
44
|
+
* The `digestStringAsync()` method of `Crypto` generates a digest of the supplied `data` string with the provided digest `algorithm`.
|
|
45
|
+
* A digest is a short fixed-length value derived from some variable-length input. **Cryptographic digests** should exhibit _collision-resistance_,
|
|
46
|
+
* meaning that it's very difficult to generate multiple inputs that have equal digest values.
|
|
47
|
+
* You can specify the returned string format as one of `CryptoEncoding`. By default, the resolved value will be formatted as a `HEX` string.
|
|
48
|
+
* On web, this method can only be called from a secure origin (https) otherwise an error will be thrown.
|
|
49
|
+
*
|
|
50
|
+
* @param algorithm The cryptographic hash function to use to transform a block of data into a fixed-size output.
|
|
51
|
+
* @param data The value that will be used to generate a digest.
|
|
52
|
+
* @param options Format of the digest string. Defaults to: `CryptoDigestOptions.HEX`.
|
|
53
|
+
* @return Return a Promise which fulfills with a value representing the hashed input.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const digest = await Crypto.digestStringAsync(
|
|
58
|
+
* Crypto.CryptoDigestAlgorithm.SHA512,
|
|
59
|
+
* '🥓 Easy to Digest! 💙'
|
|
60
|
+
* );
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
42
63
|
export async function digestStringAsync(
|
|
43
64
|
algorithm: CryptoDigestAlgorithm,
|
|
44
65
|
data: string,
|
package/src/Crypto.types.ts
CHANGED
|
@@ -1,26 +1,58 @@
|
|
|
1
|
+
// @needsAudit
|
|
2
|
+
/**
|
|
3
|
+
* [`Cryptographic hash function`](https://developer.mozilla.org/en-US/docs/Glossary/Cryptographic_hash_function)
|
|
4
|
+
*/
|
|
1
5
|
export enum CryptoDigestAlgorithm {
|
|
2
6
|
/**
|
|
3
|
-
*
|
|
4
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#SHA-1
|
|
7
|
+
* `160` bits.
|
|
5
8
|
*/
|
|
6
9
|
SHA1 = 'SHA-1',
|
|
10
|
+
/**
|
|
11
|
+
* `256` bits. Collision Resistant.
|
|
12
|
+
*/
|
|
7
13
|
SHA256 = 'SHA-256',
|
|
14
|
+
/**
|
|
15
|
+
* `384` bits. Collision Resistant.
|
|
16
|
+
*/
|
|
8
17
|
SHA384 = 'SHA-384',
|
|
18
|
+
/**
|
|
19
|
+
* `512` bits. Collision Resistant.
|
|
20
|
+
*/
|
|
9
21
|
SHA512 = 'SHA-512',
|
|
10
22
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
23
|
+
* `128` bits.
|
|
24
|
+
* @platform ios
|
|
13
25
|
*/
|
|
14
26
|
MD2 = 'MD2',
|
|
27
|
+
/**
|
|
28
|
+
* `128` bits.
|
|
29
|
+
* @platform ios
|
|
30
|
+
*/
|
|
15
31
|
MD4 = 'MD4',
|
|
32
|
+
/**
|
|
33
|
+
* `128` bits.
|
|
34
|
+
* @platform android
|
|
35
|
+
* @platform ios
|
|
36
|
+
*/
|
|
16
37
|
MD5 = 'MD5',
|
|
17
38
|
}
|
|
18
39
|
|
|
40
|
+
// @needsAudit
|
|
19
41
|
export enum CryptoEncoding {
|
|
20
42
|
HEX = 'hex',
|
|
43
|
+
/**
|
|
44
|
+
* Has trailing padding. Does not wrap lines. Does not have a trailing newline.
|
|
45
|
+
*/
|
|
21
46
|
BASE64 = 'base64',
|
|
22
47
|
}
|
|
23
48
|
|
|
24
|
-
|
|
49
|
+
// @needsAudit
|
|
50
|
+
export type CryptoDigestOptions = {
|
|
51
|
+
/**
|
|
52
|
+
* Format the digest is returned in.
|
|
53
|
+
*/
|
|
54
|
+
encoding: CryptoEncoding;
|
|
55
|
+
};
|
|
25
56
|
|
|
57
|
+
// @docsMissing
|
|
26
58
|
export type Digest = string;
|
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/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