中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
import { BusinessError } from '@kit.BasicServicesKit'; import { cryptoFramework } from '@kit.CryptoArchitectureKit'; import { userAuth } from '@kit.UserAuthenticationKit'; try { const rand = cryptoFramework.createRandom(); const len: number = 16; const randData: Uint8Array = rand?.generateRandomSync(len)?.data; const authParam: userAuth.AuthParam = { challenge: randData, authType: [userAuth.UserAuthType.PIN, userAuth.UserAuthType.FACE], authTrustLevel: userAuth.AuthTrustLevel.ATL3, }; const widgetParam: userAuth.WidgetParam = { title: '请进行身份认证', }; const userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); console.info('get userAuth instance success'); userAuthInstance.on('result', { onResult(result) { console.info(`userAuthInstance callback result: ${JSON.stringify(result)}`); userAuthInstance.off('result'); } }); console.info('auth on success'); userAuthInstance.start(); console.info('auth start success'); } catch (error) { const err: BusinessError = error as BusinessError; console.error(`auth catch error. Code is ${err?.code}, message is ${err?.message}`); }