[INJIMO-3192]: Integrate swift error response enhancement (#2001)

* [INJIMOB-3192]: Native module integration for OVP error handling

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Fixing iOS build failure

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Refactoring code to move useEffect from SendVPScreenController to UI component

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Updating useOvpErrorModal while resolving merge conflicts

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Update iOs package dependencies to develop for OVP library

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Update history error messages

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Update the user declined history message

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Remove moduleClassName and use existing method

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Fix for retry scenario error messages

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Fix for sendErrorToVerifier crash

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Add Log for decline scenario

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Fix for decline crash issue

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Common method for reject Exceptions

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Modify general exception for retry scenario

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Remove comments

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3192]: Update package resolved

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

---------

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>
This commit is contained in:
balachandarg-tw
2025-07-22 15:42:05 +05:30
committed by GitHub
parent 3beca4e7f8
commit 0fe6915bb8
17 changed files with 401 additions and 295 deletions

View File

@@ -641,11 +641,11 @@
CODE_SIGN_ENTITLEMENTS = Inji/InjiRelease.entitlements;
CODE_SIGN_IDENTITY = "Apple Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = V2ABX7953Z;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = V2ABX7953Z;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = Inji/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
@@ -663,7 +663,7 @@
PRODUCT_BUNDLE_IDENTIFIER = io.mosip.inji.wallet.mobileid;
PRODUCT_NAME = Inji;
PROVISIONING_PROFILE_SPECIFIER = "match AppStore io.mosip.inji.wallet.mobileid";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "match AppStore io.mosip.inji.wallet.mobileid";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "match AppStore io.mosip.inji.wallet.mobileid";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
@@ -701,7 +701,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CXX = "";
ENABLE_STRICT_OBJC_MSGSEND = YES;

View File

@@ -19,6 +19,24 @@
"version" : "1.1.0"
}
},
{
"identity" : "base58swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/keefertaylor/Base58Swift.git",
"state" : {
"revision" : "ce8ba8aa893f7e209e9c99c35ee61d6f1235881d",
"version" : "2.1.7"
}
},
{
"identity" : "bigint",
"kind" : "remoteSourceControl",
"location" : "https://github.com/attaswift/BigInt.git",
"state" : {
"revision" : "018a5925f60f9e0523edd261de394a0898fe95b7",
"version" : "3.1.0"
}
},
{
"identity" : "crcswift",
"kind" : "remoteSourceControl",
@@ -52,7 +70,7 @@
"location" : "https://github.com/mosip/inji-openid4vp-ios-swift",
"state" : {
"branch" : "develop",
"revision" : "879995bc2b858b0d1c6265c2d38d81f60b4e4611"
"revision" : "b93f78c94cd7632f2a80e869520788abd1378621"
}
},
{
@@ -100,6 +118,15 @@
"version" : "0.3.0"
}
},
{
"identity" : "siphash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/attaswift/SipHash",
"state" : {
"revision" : "e325083424688055363bbfcb7f1a440d7d7a1bae",
"version" : "1.2.2"
}
},
{
"identity" : "swiftcbor",
"kind" : "remoteSourceControl",
@@ -128,5 +155,5 @@
}
}
],
"version" : 2
"version" : 3
}

View File

@@ -25,6 +25,7 @@ RCT_EXTERN_METHOD(shareVerifiablePresentation:(id)vpResponseMetadata
rejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(sendErrorToVerifier:(NSString *)error
:(NSString *)errorCode
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

View File

@@ -7,6 +7,7 @@ class RNOpenId4VpModule: NSObject, RCTBridgeModule {
private var openID4VP: OpenID4VP?
static func moduleName() -> String {
return "InjiOpenID4VP"
}
@@ -21,7 +22,7 @@ class RNOpenId4VpModule: NSObject, RCTBridgeModule {
reject("OPENID4VP", error.localizedDescription, error)
}
}
@objc
func authenticateVerifier(_ urlEncodedAuthorizationRequest: String,
trustedVerifierJSON: AnyObject,
@@ -52,7 +53,8 @@ class RNOpenId4VpModule: NSObject, RCTBridgeModule {
let response = try toJsonString(jsonObject: authenticationResponse)
resolve(response)
} catch {
reject("OPENID4VP", error.localizedDescription, error)
rejectWithOpenID4VPError(error, reject: reject)
}
}
}
@@ -100,7 +102,7 @@ class RNOpenId4VpModule: NSObject, RCTBridgeModule {
reject("ERROR", "Failed to serialize JSON", nil)
}
} catch {
reject("OPENID4VP", error.localizedDescription, error)
rejectWithOpenID4VPError(error, reject: reject)
}
}
}
@@ -143,7 +145,8 @@ class RNOpenId4VpModule: NSObject, RCTBridgeModule {
formattedVPTokenSigningResults[.mso_mdoc] = MdocVPTokenSigningResult(docTypeToDeviceAuthentication: docTypeToDeviceAuthentication)
default:
reject("OPENID4VP", "Credential format not supported", nil)
let error = NSError(domain: "Credential format '\(credentialFormat)' is not supported", code: 0)
rejectWithOpenID4VPError(error, reject: reject)
return
}
}
@@ -151,23 +154,32 @@ class RNOpenId4VpModule: NSObject, RCTBridgeModule {
let response = try await openID4VP?.shareVerifiablePresentation(vpTokenSigningResults: formattedVPTokenSigningResults)
resolve(response)
} catch {
reject("OPENID4VP", error.localizedDescription, error)
rejectWithOpenID4VPError(error, reject: reject)
}
}
}
@objc
func sendErrorToVerifier(_ error: String, _ errorCode: String,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
@objc
func sendErrorToVerifier(_ error: String, _ errorCode: String,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
Task {
enum VerifierError: Error {
case customError(String)
}
await openID4VP?.sendErrorToVerifier(error: VerifierError.customError(error))
resolve(true)
let exception: OpenID4VPException = {
switch errorCode {
case OpenID4VPErrorCodes.accessDenied:
return AccessDenied(message: error, className: Self.moduleName())
case OpenID4VPErrorCodes.invalidTransactionData:
return InvalidTransactionData(message: error, className: Self.moduleName())
default:
return GenericFailure(message: error, className: Self.moduleName())
}
}()
await openID4VP?.sendErrorToVerifier(error: exception)
resolve(true)
}
}
}
func toJsonString(jsonObject: AuthorizationRequest) throws -> String {
let encoder = JSONEncoder()
@@ -183,6 +195,17 @@ class RNOpenId4VpModule: NSObject, RCTBridgeModule {
static func requiresMainQueueSetup() -> Bool {
return true
}
func rejectWithOpenID4VPError(_ error: Error, reject: RCTPromiseRejectBlock) {
if let openidError = error as? OpenID4VPException {
reject(openidError.errorCode, openidError.message, openidError)
} else {
let nsError = NSError(domain: error.localizedDescription, code: 0)
reject("ERR_UNKNOWN", nsError.localizedDescription, nsError)
}
}
}
struct EncodableWrapper: Encodable {
@@ -207,7 +230,7 @@ func getWalletMetadataFromDict(_ walletMetadata: Any,
reject("OPENID4VP", "Invalid wallet metadata format", nil)
throw NSError(domain: "", code: -1, userInfo: [NSLocalizedDescriptionKey: "Invalid Wallet Metadata"])
}
var vpFormatsSupported: [FormatType: VPFormatSupported] = [:]
if let vpFormatsSupportedDict = metadata["vp_formats_supported"] as? [String: Any],
let ldpVcDict = vpFormatsSupportedDict["ldp_vc"] as? [String: Any] {
@@ -220,7 +243,7 @@ func getWalletMetadataFromDict(_ walletMetadata: Any,
} else {
vpFormatsSupported[.ldp_vc] = VPFormatSupported(algValuesSupported: nil)
}
let walletMetadataObject = try WalletMetadata(
presentationDefinitionURISupported: metadata["presentation_definition_uri_supported"] as? Bool,
vpFormatsSupported: vpFormatsSupported,