To enable a car key, a user needs to add a car key and activate it. The following figure shows the entire interaction process. For details about the relevant APIs, please refer to Wallet Kit APIs.

The car owner app calls the queryPass API to check whether the car key is enabled on the device.
If the queryPass API returns 1010220501 No card found, the car owner app calls the canAddPass API to check whether the current device supports adding the car key.
If the queryPass or canAddPass API returns 1010200003 Environment of HUAWEI Wallet Is Not Ready, the car owner app calls the initWalletEnvironment API to initialize HUAWEI Wallet and prompt the user to agree to the agreement for car key enabling or sign in to their account.
The car owner app calls the queryPassDeviceInfo API to query the device type and specify the target device ID to enhance security.
After presetting the template, the car owner app server applies for a key card and JWE data. For details, please refer to Conducting Development for the Car Owner App Server.
When a user initiates a card enabling request, the user is redirected to HUAWEI Wallet and the addPass API carrying the encoded JWE data generated in the preceding step is called to enable the car key in HUAWEI Wallet.
During card activation, the HUAWEI Wallet server needs to interact with the DK management service to authenticate the device (exchange certificate information with the car key management console), obtain the token for requesting applet personal data from the car key management console, request applet personal data, and write data to the data security chipset. For details, please refer to Activating the Card on the Car Owner App Server.
The car owner app can call the viewPass API to show the car key details page to the user in HUAWEI Wallet.
Make the car owner app call the queryPass API to check whether the car key has been enabled on the current device based on the service ID registered when applying for Wallet Kit and the unique pass ID defined when applying for the key card.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
// Service ID registered when applying for Wallet Kit.
private passType: string = '';
// Unique pass ID defined when applying for the key card.
private serialNumber: string = '';
async queryPass() {
let passStr = JSON.stringify({
passType: this.passType,
serialNumber: this.serialNumber
});
this.walletPassClient.queryPass(passStr).then((result: string) => {
console.info(`Succeeded in querying pass, result: ${result}`);
}).catch((err: BusinessError) => {
console.error(`Failed to query pass, code:${err.code}, message:${err.message}`);
})
}
build() {
// your application UI
}
} If the queryPass API returns 1010220501 No card found, the car owner app calls the canAddPass API to check whether the current device supports adding the car key.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
// Service ID registered when applying for Wallet Kit.
private passType: string = '';
// Target device type. The value **phone** indicates mobile phone.
private targetDeviceType: string = '';
async canAddPass() {
let passStr = JSON.stringify({
passType: this.passType,
targetDeviceType: this.targetDeviceType
});
this.walletPassClient.canAddPass(passStr).then((result: string) => {
console.info(`Succeeded in checking addPass, result:${result}`);
}).catch((err: BusinessError) => {
console.error(`Failed to check addPass, code:${err.code}, message:${err.message}`);
})
}
build() {
// your application UI
}
} If the queryPass or canAddPass API returns 1010200003 Environment of HUAWEI Wallet Is Not Ready, the car owner app calls the initWalletEnvironment API to initialize HUAWEI Wallet and prompt the user to agree to the agreement for car key enabling or sign in to their account.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
// Target device type. The value **phone** indicates mobile phone.
private targetDeviceType: string = '';
async initWalletEnvironment() {
let passStr = JSON.stringify({
targetDeviceType: this.targetDeviceType
});
this.walletPassClient.initWalletEnvironment(passStr).then(() => {
console.info(`Succeeded in initiating walletEnvironment`);
}).catch((err: BusinessError) => {
console.error(`Failed to initiate walletEnvironment, code:${err.code}, message:${err.message}`);
})
}
build() {
// your application UI
}
} The car owner app calls the queryPassDeviceInfo API to query the device type and specify the target device ID.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
// Service ID registered when applying for Wallet Kit.
private passType: string = '';
// Target device type. The value **phone** indicates mobile phone.
private targetDeviceType: string = '';
async queryPassDeviceInfo() {
let passStr = JSON.stringify({
passType: this.passType,
targetDeviceType: this.targetDeviceType
});
this.walletPassClient.queryPassDeviceInfo(passStr).then((result: string) => {
console.info(`Succeeded in querying passDeviceInfo, result:${result}`);
}).catch((err: BusinessError) => {
console.error(`Failed to query passDeviceInfo, code:${err.code}, message:${err.message}`);
})
}
build() {
// your application UI
}
} After presetting the template, the car owner app server applies for a key card and JWE data. For details, please refer to Conducting Development for the Car Owner App Server.
When a user initiates a card enabling request, the user is redirected to HUAWEI Wallet and the addPass API carrying the encoded JWE data generated in the preceding step is called to enable the car key in HUAWEI Wallet.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
// JWE data generated by referring to Conducting Development for the Car Owner App Server.
private jweContent: string = '';
async addPass() {
let passStr = JSON.stringify({
jweContent: this.jweContent
});
this.walletPassClient.addPass(passStr).then((result: string) => {
console.info(`Succeeded in adding pass, result:${result}`);
}).catch((err: BusinessError) => {
console.error(`Failed to add pass, code:${err.code}, message:${err.message}`);
})
}
build() {
// your application UI
}
} During card activation, the HUAWEI Wallet server needs to interact with the DK management service to authenticate the device (exchange certificate information with the car key management console), obtain the token for requesting applet personal data from the car key management console, request applet personal data, and write data to the data security chipset. For details, please refer to Activating the Card on the Car Owner App Server.
The car owner app can call the viewPass API to show the car key details page to the user in HUAWEI Wallet.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
// Service ID registered when applying for Wallet Kit.
private passType: string = '';
// Unique pass ID defined when applying for the key card.
private serialNumber: string = '';
async viewPass() {
let passStr = JSON.stringify({
passType: this.passType,
serialNumber: this.serialNumber
});
try {
await this.walletPassClient.viewPass(passStr);
console.info(`Succeeded in viewing pass`);
} catch (err) {
console.error(`Failed to view pass, code:${err.code}, message:${err.message}`);
}
}
build() {
// your application UI
}
} Download the sample code for Wallet Kit - Card Enabling on the Server and open the code using Intellij IDEA. If you do not have Intellij IDEA, download its latest version first. The directory structure of the sample code is as follows. Pay attention to the files enclosed in red boxes.

Open the resources/release.config.properties file and set the parameters based on the actual app data.

| Parameter | Description |
|---|---|
| gw.appid |
|
| gw.appid.secret | Set gw.appid and gw.appid.secret to the client ID and client secret obtained in AppGallery Connect, respectively. |
| walletServerBaseUrl | Set it to https://wallet-passentrust-drcn.cloud.huawei.com.cn/hmspass. |
| servicePrivateKey | Set it to the private key generated in step 5 of Applying for Wallet Kit. |
Open the resources/data/StdCarKeyModel.json file and set the parameters based on the actual app data. For details, please refer to the request parameters in Preset Template.

Open the stdcarkey/StdCarKeyModelTest.java file and execute the createStdCarKeyModel method. The following information is displayed on the console. For details, please refer to the response parameters in Preset Template.

Open the resources/data/StdCarKeyInstance.json file and set the parameters based on the actual app data. For details, please refer to the request parameters in Applying for a Key Card.
Open the stdcarkey/StdCarKeyInstanceTest.java file and execute the addStdCarKeyInstance method. The following information is displayed on the console. For details, please refer to the response parameters in Applying for a Key Card.

Download the sample code for Wallet Kit - Card Activation on the Server and open the code using Intellij IDEA. Complete the project configuration, and set SERVER_PUBLIC_KEY and SERVER_SECRET_KEY in the Constants class to the public key and private key generated in step 5 of Applying for Wallet Kit, respectively. Open the PassesController class.
Use the register method in the PassesController class to authenticate the device. For details, please refer to Device Authentication.

Use the requestToken method in the PassesController class to obtain the personal data token. For details, please refer to Obtaining a Personal Data Token.

Use the getPersonalInfo method in the PassesController class to obtain personal data. For details, please refer to Obtaining Personal Data. Focus on the getDevicePassData method in dealWithPersonalizeDataRequest and the generatePassData method in ICCECarKeyDevicePassUnit. Generate data according to the API description of the getPersonalizeData method.
