importFoundationimportLocalAuthenticationstructMastgTest{staticfuncmastgTest(completion:@escaping(String)->Void){lettoken="8767086b9f6f976g-a8df76"letcontext=LAContext()letreason="Authenticate to access your token"context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,localizedReason:reason){success,errorinDispatchQueue.main.async{ifsuccess{completion("✅ Retrieved token: \(token)")return}//Authenticationfailed:inspecttheerrorcodeletmessage:StringifletlaError=erroras?LAError{switchlaError.code{case.userCancel:message="Authentication was cancelled by the user."case.userFallback:message="User tapped the fallback button (e.g. entered a password)."case.systemCancel:message="Authentication was cancelled by the system (e.g. another app came to foreground)."case.passcodeNotSet:message="Passcode is not set on the device."case.biometryNotAvailable:message="No biometric authentication is available on this device."case.biometryNotEnrolled:message="The user has not enrolled any biometrics."case.biometryLockout:message="Biometry is locked out due to too many failed attempts."default://Foranyfutureorundocumentedcodesmessage=laError.localizedDescription}}else{//Someothernon‐LAErrorerrormessage=error?.localizedDescription??"Unknown authentication error."}completion("❌ \(message)")}}}}
Interceptor.attach(ObjC.classes.LAContext["- evaluatePolicy:localizedReason:reply:"].implementation,{onEnter(args){constLAPolicy={1:".deviceOwnerAuthenticationWithBiometrics",2:".deviceOwnerAuthentication"3:".deviceOwnerAuthenticationWithWatch",4:".deviceOwnerAuthenticationWithBiometricsOrWatch",5:".deviceOwnerAuthenticationWithWristDetection",};constpolicy=args[2].toInt32();constpolicyDescription=LAPolicy[policy]||"Unknown Policy";console.log(`\nLAContext.canEvaluatePolicy(${args[2]}) called with ${policyDescription} (${args[2]})\n`);// Use an arrow function so that `this` remains the same as in onEnterconstprintBacktrace=(maxLines=8)=>{console.log("\nBacktrace:");letbacktrace=Thread.backtrace(this.context,Backtracer.ACCURATE).map(DebugSymbol.fromAddress);for(leti=0;i<Math.min(maxLines,backtrace.length);i++){console.log(backtrace[i]);}}printBacktrace();}});
LAContext.canEvaluatePolicy(0x1)calledwith.deviceOwnerAuthenticationWithBiometrics(0x1)Backtrace:0x10095c35cMASTestApp!specializedstaticMastgTest.mastgTest(completion:)0x10095d4b4MASTestApp!closure#1 in closure #1 in closure #1 in ContentView.body.getter0x19f6cbc54SwiftUI!partialapplyforclosure#1 in closure #2 in ContextMenuBridge.contextMenuInteraction(_:willPerformPreviewActionForMenuWith:animator:)0x19f5d86d0SwiftUI!partialapplyforspecializedthunkfor@callee_guaranteed()->(@outA,@error@ownedError)0x19fca57c4SwiftUI!specializedstaticMainActor.assumeIsolated<A>(_:file:line:)0x19fc721a8SwiftUI!ButtonAction.callAsFunction()0x19f154c2cSwiftUI!partialapplyforimplicitclosure#2 in implicit closure #1 in PlatformItemListButtonStyle.makeBody(configuration:)0x19f6813b4SwiftUI!ButtonBehavior.ended()
The test fails because the output only shows calls to biometric verification with LocalAuthentication API and no calls to any Keychain APIs requiring user presence (SecAccessControlCreateWithFlags).