Error Domain=NSCocoaErrorDomain Code=3840 “Invalid value around line 1, column 0

Description of the problem: In an iOS client, I am using the SFA (Secure Field Authorization) method from web3Auth to obtain a public-private key pair. Sometimes it is successful, but sometimes it fails.
code:

    @objc class func getPrivateKeyInfo(idToken: String) async -> [String: Any]? {
        let jwt = try? decode(jwt: idToken)
        let verifierId = jwt?.claim(name: "open_id").string
                
        let authArgs = SingleFactorAuthArgs(network: TorusNetwork.TESTNET)
        let singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: authArgs)
        let loginParams = LoginParams(verifier: SPARKLE_VERIFIER, verifierId: verifierId ?? "", idToken: idToken)
        
        do {
            let torusKey = try await singleFactoreAuth.getKey(loginParams: loginParams)
            let privateKey = torusKey.getPrivateKey()
            let publicAddress = torusKey.getPublicAddress()
            
            var infoDic: [String: String?] = [:]
            if (!privateKey.isEmpty) {
                infoDic["privateKey"] = privateKey
            }
            
            if (!publicAddress.isEmpty) {
                infoDic["publicAddress"] = publicAddress
            }
            
            print("Web3AuthInterface getPrivateKeyInfo success.")
            return infoDic as [String : Any]
        } catch {
            print("Web3AuthInterface getPrivateKeyInfo fail, error:\(error).")
            return nil
        }
    }

The parameter “id_token” is:
eyJhbGciOiJSUzI1NiIsImtpZCI6InVuaVBhc3NfMjAyMzA1MTYiLCJ0eXAiOiJKV1QifQ.eyJvcGVuX2lkIjoiZDkxYWZjNTYtZjBlYy00YzViLThhNjAtMTMzNWQ5YWQ1M2FlIiwiaXNzIjoic3BhcmtsZSIsImV4cCI6MTY5NDQzMDM4MCwibmJmIjoxNjk0NDIzMTgwLCJpYXQiOjE2OTQ0MjMxODB9.pAt79GkaTVFqgFWB53qNf0DFaT7wVPTgetKHIYkL3uHtGPjnZQaMayZIE_KG1B-wrwfz109j0Hi4sL_1akzcf0O2elPgFMtwRCj0E80kPBKy0dXu8lg-KAtZf1B8vk_RhgN1fo6i-D7C-uiUC_GcygVFY4_EZ2MIpJQMTIv5VFFH_8BnHg_CRcxN092bqbONNC1t8DSTcXwhatiON4zIyF6xpq8vayDkKPuiKvu_ERU7tXxK6ZEfubcgCFhBTs261P5Qum9n8jC6KCunfboa-d4GQUkwTp_k3kwPuXa8f0us37BvO2tKVa-b0XkLDm2h7wpv9660xYon9_ERoXbJFg

error msg:
error:dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: “The given data was not valid JSON.“, underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 “Invalid value around line 1, column 0.” UserInfo={NSDebugDescription=Invalid value around line 1, column 0., NSJSONSerializationErrorIndex=0})))

it indicate the JSON is invalid from error msg. but it seems ok after I parse it. so how can I solve this problem? sometimes it goes well, sometimes it fail. any possiblility from the network?

@dev16 Thanks for reaching out.

I will review this and get back with an update.

A few questions here:

  1. May I know how you obtained the token? The idtoken displays an invalid signature as per (jwt.io decoded)
  1. Have you followed the installation as per Installing SFA iOS SDK | Documentation | Web3Auth
  2. Can you share these fields:
  • Verifier Identifier:
  • JWT Verifier ID:
  • JWK Endpoint:
  • JWT Validation:
  • SDK version:
  1. Which example are you using to guide your code? We have a few available here.
  1. I obtain the idToken from my server. The idtoken displays Signature Verified as per (jwt.io decoded)
    I entered the public key:
    -----BEGIN PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu1SU1LfVLPHCozMxH2Mo
    4lgOEePzNm0tRgeLezV6ffAt0gunVTLw7onLRnrq0/IzW7yWR7QkrmBL7jTKEn5u
    +qKhbwKfBstIs+bMY2Zkp18gnTxKLxoS2tFczGkPLPgizskuemMghRniWaoLcyeh
    kd3qqGElvW/VDL5AaWTg0nLVkjRo9z+40RQzuVaE8AkAFmxZzow3x+VJYKdjykkJ
    0iT9wCS0DRTXu269V264Vf/3jvredZiKRkgwlL9xNAwxXFg0x/XFw005UWVRIkdg
    cKWTjpBP2dPwVZ4WWC+9aGVd+Gyn1o0CLelf4rEjGoXbAAEgAqeGUxrcIlbjXfbc
    mwIDAQAB
    -----END PUBLIC KEY-----

The payload exp field is set to be valid for 2 hours.


  1. I have followed the installation as per Installing SFA iOS SDK | Documentation | Web3Auth

3.My web3Auth dashboard setting:

loginParams
verifier:Sparkle-Custom-Auth-01
verifierId:open_id
JWTDecode version:3.0.0

4.I refer to this example code.

I have forwarded your issue to our Dev team and we will get back with further updates.

Thanks, look forward to your reply.

@dev16 Does it fails rarely or ocassionally? Any observation on that?

@dev16 Could you please reply with the information requested?

Do join our upcoming community call - Web3Auth Community Call #4 · Zoom · Luma