Skip to content

Commit 8b1125e

Browse files
[app-integrity] - rename app integrity functions (expo#40447)
# Why Functions in app-integrity were missing `async` suffix. Thanks to @vonovak for catching. It's a breaking change, but should be fine since it is still in alpha. <!-- Please describe the motivation for this PR, and link to relevant GitHub issues, forums posts, or feature requests. --> # How Add `async` suffix to function names. Updated `unversioned` doc, will make a PR for updating latest publish after we release the new version. <!-- How did you build this feature or fix this bug and why? --> # Test Plan Tested NCL example on android and iOS. <!-- Please describe how you tested this change and how a reviewer could reproduce your test, especially if this PR does not include automated tests! If possible, please also provide terminal output and/or screenshots demonstrating your test/reproduction. --> # Checklist <!-- Please check the appropriate items below if they apply to your diff. --> - [x] I added a `changelog.md` entry and rebuilt the package sources according to [this short guide](https://github.com/expo/expo/blob/main/CONTRIBUTING.md#-before-submitting) - [x] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). - [x] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
1 parent 48ce70c commit 8b1125e

File tree

18 files changed

+141
-137
lines changed

18 files changed

+141
-137
lines changed

apps/native-component-list/src/screens/AppIntegrity/AppIntegrityScreen.android.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function AppIntegrityAndroidScreen() {
2121
useEffect(() => {
2222
const checkHardwareAttestationSupport = async () => {
2323
try {
24-
const supported = await AppIntegrity.isHardwareAttestationSupported();
24+
const supported = await AppIntegrity.isHardwareAttestationSupportedAsync();
2525
setHardwareAttestationSupported(supported);
2626
addResult(`Hardware attestation supported: ${supported}`);
2727
} catch (error) {
@@ -36,10 +36,10 @@ export default function AppIntegrityAndroidScreen() {
3636
const testPrepareIntegrityTokenProvider = async () => {
3737
setIsLoading(true);
3838
try {
39-
await AppIntegrity.prepareIntegrityTokenProvider('1234567890');
40-
addResult('prepareIntegrityTokenProvider: Success');
39+
await AppIntegrity.prepareIntegrityTokenProviderAsync('1234567890');
40+
addResult('prepareIntegrityTokenProviderAsync: Success');
4141
} catch (error) {
42-
addResult(`prepareIntegrityTokenProvider error: ${error}`);
42+
addResult(`prepareIntegrityTokenProviderAsync error: ${error}`);
4343
} finally {
4444
setIsLoading(false);
4545
}
@@ -49,10 +49,10 @@ export default function AppIntegrityAndroidScreen() {
4949
setIsLoading(true);
5050
try {
5151
const challenge = 'test-challenge-' + Date.now();
52-
const token = await AppIntegrity.requestIntegrityCheck(challenge);
53-
addResult(`requestIntegrityCheck: Success (token length: ${token.length})`);
52+
const token = await AppIntegrity.requestIntegrityCheckAsync(challenge);
53+
addResult(`requestIntegrityCheckAsync: Success (token length: ${token.length})`);
5454
} catch (error) {
55-
addResult(`requestIntegrityCheck error: ${error}`);
55+
addResult(`requestIntegrityCheckAsync error: ${error}`);
5656
} finally {
5757
setIsLoading(false);
5858
}
@@ -61,12 +61,12 @@ export default function AppIntegrityAndroidScreen() {
6161
const testFullFlow = async () => {
6262
setIsLoading(true);
6363
try {
64-
await AppIntegrity.prepareIntegrityTokenProvider('1234567890');
65-
addResult('prepareIntegrityTokenProvider: Success');
64+
await AppIntegrity.prepareIntegrityTokenProviderAsync('1234567890');
65+
addResult('prepareIntegrityTokenProviderAsync: Success');
6666

6767
const challenge = 'test-challenge-' + Date.now();
68-
const token = await AppIntegrity.requestIntegrityCheck(challenge);
69-
addResult(`requestIntegrityCheck: Success (token length: ${token.length})`);
68+
const token = await AppIntegrity.requestIntegrityCheckAsync(challenge);
69+
addResult(`requestIntegrityCheckAsync: Success (token length: ${token.length})`);
7070
} catch (error) {
7171
addResult(`Full flow error: ${error}`);
7272
} finally {
@@ -80,11 +80,11 @@ export default function AppIntegrityAndroidScreen() {
8080
const keyAlias = 'test_key';
8181
const challenge = 'hw_challenge';
8282

83-
await AppIntegrity.generateHardwareAttestedKey(keyAlias, challenge);
84-
addResult(`generateHardwareAttestedKey: Success (alias: ${keyAlias})`);
83+
await AppIntegrity.generateHardwareAttestedKeyAsync(keyAlias, challenge);
84+
addResult(`generateHardwareAttestedKeyAsync: Success (alias: ${keyAlias})`);
8585
setLastGeneratedKeyAlias(keyAlias);
8686
} catch (error) {
87-
addResult(`generateHardwareAttestedKey error: ${error}`);
87+
addResult(`generateHardwareAttestedKeyAsync error: ${error}`);
8888
} finally {
8989
setIsLoading(false);
9090
}
@@ -98,7 +98,7 @@ export default function AppIntegrityAndroidScreen() {
9898
addResult(`No key alias found. Please generate a key first.`);
9999
return;
100100
}
101-
const certificates = await AppIntegrity.getAttestationCertificateChain(keyAlias);
101+
const certificates = await AppIntegrity.getAttestationCertificateChainAsync(keyAlias);
102102

103103
addResult(`getAttestationCertificateChain: Success`);
104104
addResult(`Certificate chain length: ${certificates.length}`);
@@ -120,10 +120,10 @@ export default function AppIntegrityAndroidScreen() {
120120
const keyAlias = 'full_flow_key';
121121
const challenge = 'full_challenge';
122122

123-
await AppIntegrity.generateHardwareAttestedKey(keyAlias, challenge);
123+
await AppIntegrity.generateHardwareAttestedKeyAsync(keyAlias, challenge);
124124
addResult(`✓ Generated hardware-attested key: ${keyAlias}`);
125125

126-
const certificates = await AppIntegrity.getAttestationCertificateChain(keyAlias);
126+
const certificates = await AppIntegrity.getAttestationCertificateChainAsync(keyAlias);
127127
addResult(`✓ Retrieved certificate chain (${certificates.length} certificates)`);
128128
// console.log('certificates ', certificates);
129129

@@ -161,11 +161,11 @@ export default function AppIntegrityAndroidScreen() {
161161
style={styles.button}
162162
onPress={testPrepareIntegrityTokenProvider}
163163
disabled={isLoading}>
164-
<Text style={styles.buttonText}>Test prepareIntegrityTokenProvider</Text>
164+
<Text style={styles.buttonText}>Test prepareIntegrityTokenProviderAsync</Text>
165165
</Pressable>
166166

167167
<Pressable style={styles.button} onPress={testRequestIntegrityCheck} disabled={isLoading}>
168-
<Text style={styles.buttonText}>Test requestIntegrityCheck</Text>
168+
<Text style={styles.buttonText}>Test requestIntegrityCheckAsync</Text>
169169
</Pressable>
170170

171171
<Pressable style={styles.button} onPress={testFullFlow} disabled={isLoading}>

apps/native-component-list/src/screens/AppIntegrity/AppIntegrityScreen.ios.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ export default function AppIntegrityIOSScreen() {
1414
setResults([]);
1515
};
1616

17-
const testGenerateKey = async () => {
17+
const testGenerateKeyAsync = async () => {
1818
setIsLoading(true);
1919
try {
20-
const key = await AppIntegrity.generateKey();
21-
addResult(`generateKey: Success (key: ${key})`);
20+
const key = await AppIntegrity.generateKeyAsync();
21+
addResult(`generateKeyAsync: Success (key: ${key})`);
2222
} catch (error) {
23-
addResult(`generateKey error: ${error}`);
23+
addResult(`generateKeyAsync error: ${error}`);
2424
} finally {
2525
setIsLoading(false);
2626
}
2727
};
2828

29-
const testAttestKey = async () => {
29+
const testAttestKeyAsync = async () => {
3030
setIsLoading(true);
3131
try {
32-
const key = await AppIntegrity.generateKey();
32+
const key = await AppIntegrity.generateKeyAsync();
3333
addResult(`Generated key: ${key}`);
3434
const challenge = 'test-challenge-' + Date.now();
35-
const attestation = await AppIntegrity.attestKey(key, challenge);
36-
addResult(`attestKey: Success (attestation length: ${attestation.length})`);
35+
const attestation = await AppIntegrity.attestKeyAsync(key, challenge);
36+
addResult(`attestKeyAsync: Success (attestation length: ${attestation.length})`);
3737
} catch (error) {
38-
addResult(`attestKey error: ${error}`);
38+
addResult(`attestKeyAsync error: ${error}`);
3939
} finally {
4040
setIsLoading(false);
4141
}
@@ -44,14 +44,14 @@ export default function AppIntegrityIOSScreen() {
4444
const testAssertion = async () => {
4545
setIsLoading(true);
4646
try {
47-
const key = await AppIntegrity.generateKey();
48-
addResult(`generateKey: Success (key: ${key})`);
47+
const key = await AppIntegrity.generateKeyAsync();
48+
addResult(`generateKeyAsync: Success (key: ${key})`);
4949
const challenge = 'test-challenge-' + Date.now();
50-
const attestation = await AppIntegrity.attestKey(key, challenge);
51-
addResult(`attestKey: Success (attestation length: ${attestation.length})`);
50+
const attestation = await AppIntegrity.attestKeyAsync(key, challenge);
51+
addResult(`attestKeyAsync: Success (attestation length: ${attestation.length})`);
5252
const challengeData = JSON.stringify({ timestamp: Date.now(), test: true });
53-
const assertion = await AppIntegrity.generateAssertion(key, challengeData);
54-
addResult(`generateAssertion: Success (assertion length: ${assertion.length})`);
53+
const assertion = await AppIntegrity.generateAssertionAsync(key, challengeData);
54+
addResult(`generateAssertionAsync: Success (assertion length: ${assertion.length})`);
5555
} catch (error) {
5656
addResult(`Full flow error: ${error}`);
5757
} finally {
@@ -67,16 +67,16 @@ export default function AppIntegrityIOSScreen() {
6767
<Text style={styles.subtitle}>isSupported: {AppIntegrity.isSupported.toString()}</Text>
6868
</View>
6969
<View style={styles.buttonContainer}>
70-
<Pressable style={styles.button} onPress={testGenerateKey} disabled={isLoading}>
71-
<Text style={styles.buttonText}>Test generateKey</Text>
70+
<Pressable style={styles.button} onPress={testGenerateKeyAsync} disabled={isLoading}>
71+
<Text style={styles.buttonText}>Test generateKeyAsync</Text>
7272
</Pressable>
7373

74-
<Pressable style={styles.button} onPress={testAttestKey} disabled={isLoading}>
75-
<Text style={styles.buttonText}>Test attestKey</Text>
74+
<Pressable style={styles.button} onPress={testAttestKeyAsync} disabled={isLoading}>
75+
<Text style={styles.buttonText}>Test attestKeyAsync</Text>
7676
</Pressable>
7777

7878
<Pressable style={styles.button} onPress={testAssertion} disabled={isLoading}>
79-
<Text style={styles.buttonText}>Test Assertion</Text>
79+
<Text style={styles.buttonText}>Test generateAssertionAsync</Text>
8080
</Pressable>
8181

8282
<Pressable style={[styles.button, styles.clearButton]} onPress={clearResults}>

docs/pages/versions/unversioned/sdk/app-integrity.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ You need to prepare the integrity token provider before you make integrity check
3939
import * as AppIntegrity from '@expo/app-integrity';
4040

4141
const cloudProjectNumber = 'your-cloud-project-number';
42-
await AppIntegrity.prepareIntegrityTokenProvider(cloudProjectNumber);
42+
await AppIntegrity.prepareIntegrityTokenProviderAsync(cloudProjectNumber);
4343
```
4444

4545
### Request an integrity token (on demand)
@@ -48,16 +48,16 @@ Whenever your app makes a server request that you want to check is genuine, you
4848

4949
```js
5050
const requestHash = '2cp24z...';
51-
const result = await AppIntegrity.requestIntegrityCheck(requestHash);
51+
const result = await AppIntegrity.requestIntegrityCheckAsync(requestHash);
5252
```
5353

54-
Before calling [requestIntegrityCheck](#appintegrityrequestintegritycheckrequesthash), ensure that [prepareIntegrityTokenProvider](#appintegrityprepareintegritytokenprovidercloudprojectnumber) was called successfully.
54+
Before calling [requestIntegrityCheckAsync](#appintegrityrequestintegritycheckasyncrequesthash), ensure that [prepareIntegrityTokenProviderAsync](#appintegrityprepareintegritytokenproviderasynccloudprojectnumber) was called successfully.
5555

56-
In this example, `requestHash` is a hash unique to the specific user action being verified. You can call [requestIntegrityCheck](#appintegrityprepareintegritytokenprovidercloudprojectnumber) multiple times with different hashes for different user actions.
56+
In this example, `requestHash` is a hash unique to the specific user action being verified. You can call [requestIntegrityCheckAsync](#appintegrityprepareintegritytokenproviderasynccloudprojectnumber) multiple times with different hashes for different user actions.
5757

5858
On success, send the result to your server for verification.
5959

60-
> **Note**: If your app uses the same token provider for too long, the token provider can expire which results in the `ERR_APP_INTEGRITY_PROVIDER_INVALID` error on the next token request. You should handle this error by requesting a new provider by calling `prepareIntegrityTokenProvider` again.
60+
> **Note**: If your app uses the same token provider for too long, the token provider can expire which results in the `ERR_APP_INTEGRITY_PROVIDER_INVALID` error on the next token request. You should handle this error by requesting a new provider by calling `prepareIntegrityTokenProviderAsync` again.
6161
6262
### Decrypt and verify the integrity verdict
6363

@@ -105,7 +105,7 @@ if (AppIntegrity.isSupported) {
105105
For each user account on each device running your app, generate a unique, hardware-based, cryptographic key pair by calling the `generateKey` method.
106106

107107
```js
108-
const keyId = await AppIntegrity.generateKey();
108+
const keyId = await AppIntegrity.generateKeyAsync();
109109
```
110110

111111
On success, the method returns a key identifier (`keyId`) that you use later to access the key. Record the identifier in persistent storage because there's no way to use the key without the identifier and no way to get the identifier later. The device automatically stores the associated private key in the Secure Enclave, from where the App Attest service can use it to create signatures, but from where no process can ever directly read or modify it, ensuring its security.
@@ -123,7 +123,7 @@ Request a unique, one-time challenge from your server. This challenge will be em
123123
Pass the `keyId` alongwith the challenge from your server created in the previous steps in `attestKey` method as shown below:
124124

125125
```js
126-
const attestationObject = await AppIntegrity.attestKey(keyId, challenge);
126+
const attestationObject = await AppIntegrity.attestKeyAsync(keyId, challenge);
127127
```
128128

129129
On success, send the received `attestationObject` and the `keyId` to your server for verification.
@@ -145,7 +145,7 @@ const request = {
145145
levelId: '1234',
146146
challenge: challenge,
147147
};
148-
const assertion = await AppIntegrity.generateAssertion(keyId, JSON.stringify(request));
148+
const assertion = await AppIntegrity.generateAssertionAsync(keyId, JSON.stringify(request));
149149
```
150150

151151
On success, pass the assertion object, along with the client data, to the server. If the assertion object fails verification, it's your responsibility to decide how to handle the request.

0 commit comments

Comments
 (0)