1e41f4b71Sopenharmony_ci# @ohos.deviceAttest (Device Attestation) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **deviceAttest** module provides attestation of devices in OpenHarmony by comparing the device information with that stored in the cloud. 4e41f4b71Sopenharmony_ciYou can use the APIs provided by the **deviceAttest** module to obtain the device attestation result. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci> **NOTE** 7e41f4b71Sopenharmony_ci> 8e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 9e41f4b71Sopenharmony_ci> 10e41f4b71Sopenharmony_ci> - The APIs provided by this module are system APIs. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci## Modules to Import 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci```ts 15e41f4b71Sopenharmony_ciimport deviceAttest from '@ohos.deviceAttest'; 16e41f4b71Sopenharmony_ci``` 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci## deviceAttest.getAttestStatus 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_cigetAttestStatus(callback: AsyncCallback<AttestResultInfo>) : void 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciObtains details about the device attestation result from the cloud. This API uses an asynchronous callback to return the result. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**System capability**: SystemCapability.XTS.DeviceAttest 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**Parameters** 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 29e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 30e41f4b71Sopenharmony_ci| callback | AsyncCallback<[AttestResultInfo](#attestresultinfo)> | Yes | Callback invoked to return the result. If the operation is successful, **error** is **undefined**, and **result** is the obtained [AttestResultInfo](#attestresultinfo). Otherwise, **error** is an error object.| 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**Error codes** 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci| ID | Error Message | 35e41f4b71Sopenharmony_ci|----------|----------------------| 36e41f4b71Sopenharmony_ci| 20000001 | system service exception. | 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci**Example** 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci```ts 41e41f4b71Sopenharmony_ciimport base from '@ohos.base'; 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_citry { 44e41f4b71Sopenharmony_ci deviceAttest.getAttestStatus((error: base.BusinessError, value: deviceAttest.AttestResultInfo) => { 45e41f4b71Sopenharmony_ci if (typeof error != 'undefined') { 46e41f4b71Sopenharmony_ci console.info("error code:" + error.code + " message:" + error.message); 47e41f4b71Sopenharmony_ci } else { 48e41f4b71Sopenharmony_ci console.info("auth:" + value.authResult + " software:" + value.softwareResult + " ticket:" + value.ticket); 49e41f4b71Sopenharmony_ci console.info("versionIdResult:" + value.softwareResultDetail[0], 50e41f4b71Sopenharmony_ci " patchLevelResult:" + value.softwareResultDetail[1], 51e41f4b71Sopenharmony_ci " rootHashResult:" + value.softwareResultDetail[2], 52e41f4b71Sopenharmony_ci " PCIDResult:" + value.softwareResultDetail[3], 53e41f4b71Sopenharmony_ci " reserver:" + value.softwareResultDetail[4]); 54e41f4b71Sopenharmony_ci } 55e41f4b71Sopenharmony_ci }) 56e41f4b71Sopenharmony_ci} catch (error) { 57e41f4b71Sopenharmony_ci let code: number = (error as base.BusinessError).code; 58e41f4b71Sopenharmony_ci let message: string = (error as base.BusinessError).message; 59e41f4b71Sopenharmony_ci console.info("error code:" + code + " message:" + message); 60e41f4b71Sopenharmony_ci} 61e41f4b71Sopenharmony_ci``` 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci## deviceAttest.getAttestStatus 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_cigetAttestStatus() : Promise<AttestResultInfo> 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ciObtains details about the device attestation result from the cloud. This API uses a promise to return the result. 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci**System capability**: SystemCapability.XTS.DeviceAttest 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**Return value** 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci| Type | Description | 74e41f4b71Sopenharmony_ci| ----------------------------------------------------- | ------------------------------- | 75e41f4b71Sopenharmony_ci| Promise<[AttestResultInfo](#attestresultinfo)> | Promise used to return the device attestation information obtained.| 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci**Error codes** 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci| ID | Error Message | 80e41f4b71Sopenharmony_ci|----------|----------------------| 81e41f4b71Sopenharmony_ci| 20000001 | system service exception. | 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**Example** 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci```ts 86e41f4b71Sopenharmony_ciimport base from '@ohos.base'; 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_citry { 89e41f4b71Sopenharmony_ci deviceAttest.getAttestStatus().then((value: deviceAttest.AttestResultInfo) => { 90e41f4b71Sopenharmony_ci console.info("auth:" + value.authResult + " software:" + value.softwareResult + " ticket:" + value.ticket); 91e41f4b71Sopenharmony_ci console.info("versionIdResult:" + value.softwareResultDetail[0], 92e41f4b71Sopenharmony_ci " patchLevelResult:" + value.softwareResultDetail[1], 93e41f4b71Sopenharmony_ci " rootHashResult:" + value.softwareResultDetail[2], 94e41f4b71Sopenharmony_ci " PCIDResult:" + value.softwareResultDetail[3], 95e41f4b71Sopenharmony_ci " reserver:" + value.softwareResultDetail[4]); 96e41f4b71Sopenharmony_ci }).catch((error: base.BusinessError) => { 97e41f4b71Sopenharmony_ci console.info("error code:" + error.code + " message:" + error.message); 98e41f4b71Sopenharmony_ci }); 99e41f4b71Sopenharmony_ci} catch (error) { 100e41f4b71Sopenharmony_ci let code: number = (error as base.BusinessError).code; 101e41f4b71Sopenharmony_ci let message: string = (error as base.BusinessError).message; 102e41f4b71Sopenharmony_ci console.info("error code:" + code + " message:" + message); 103e41f4b71Sopenharmony_ci} 104e41f4b71Sopenharmony_ci``` 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci## deviceAttest.getAttestStatusSync 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_cigetAttestStatusSync() : AttestResultInfo 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ciObtains details about the device attestation result from the cloud synchronously. 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**System capability**: SystemCapability.XTS.DeviceAttest 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci**Return value** 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci| Type | Description | 117e41f4b71Sopenharmony_ci| ----------------------------------------------------- | ------------------------------- | 118e41f4b71Sopenharmony_ci| [AttestResultInfo](#attestresultinfo) | Returns the device attestation information obtained.| 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**Error codes** 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci| ID | Error Message | 123e41f4b71Sopenharmony_ci|----------|----------------------| 124e41f4b71Sopenharmony_ci| 20000001 | system service exception. | 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**Example** 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci```ts 129e41f4b71Sopenharmony_ciimport base from '@ohos.base'; 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_citry { 132e41f4b71Sopenharmony_ci let value: deviceAttest.AttestResultInfo = deviceAttest.getAttestStatusSync(); 133e41f4b71Sopenharmony_ci console.info("auth:" + value.authResult + " software:" + value.softwareResult + " ticket:" + value.ticket); 134e41f4b71Sopenharmony_ci console.info("versionIdResult:" + value.softwareResultDetail[0], 135e41f4b71Sopenharmony_ci " patchLevelResult:" + value.softwareResultDetail[1], 136e41f4b71Sopenharmony_ci " rootHashResult:" + value.softwareResultDetail[2], 137e41f4b71Sopenharmony_ci " PCIDResult:" + value.softwareResultDetail[3], 138e41f4b71Sopenharmony_ci " reserver:" + value.softwareResultDetail[4]); 139e41f4b71Sopenharmony_ci} catch (error) { 140e41f4b71Sopenharmony_ci let code: number = (error as base.BusinessError).code; 141e41f4b71Sopenharmony_ci let message: string = (error as base.BusinessError).message; 142e41f4b71Sopenharmony_ci console.info("error code:" + code + " message:" + message); 143e41f4b71Sopenharmony_ci} 144e41f4b71Sopenharmony_ci``` 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci## AttestResultInfo 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ciDefines the device attestation result information. 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci**System capability**: SystemCapability.XTS.DeviceAttest 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci| Name | Type | Readable| Writable| Description | 153e41f4b71Sopenharmony_ci| --------------------- | --------------------- | ---- | ---- | ---------------------- | 154e41f4b71Sopenharmony_ci| authResult | number | Yes | No | Device hardware attestation result. | 155e41f4b71Sopenharmony_ci| softwareResult | number | Yes | No | Device software attestation result. | 156e41f4b71Sopenharmony_ci| softwareResultDetail | Array<number> | Yes | No | Detailed information about the device software attestation result.<br> - **softwareResultDetail[0]**: version ID attestation result.<br>- **softwareResultDetail[1]**: attestation result of the security patch label.<br>- **softwareResultDetail[2]**: version hash attestation result.<br>- **softwareResultDetail[3]**: attestation result of the system capability set.<br>- **softwareResultDetail[4]**: reserved. | 157e41f4b71Sopenharmony_ci| ticket | string | Yes | No | Soft certificate delivered by the cloud.<br>If the device hardware attestation is successful, a value is returned. If the attestation fails, this parameter is empty. | 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci> **NOTE** 160e41f4b71Sopenharmony_ci> 161e41f4b71Sopenharmony_ci> - The attestation result of device hardware and software information can be any of the following:<br> - **-2**: No attestation is performed.<br>- **-1**: The attestation fails.<br>- **0**: The attestation is successful. 162