phantom / docs

31 stars 17 forks source link

(iOS) Getting -32603 error from Universal link authorization #29

Closed mejiagarcia closed 2 years ago

mejiagarcia commented 2 years ago

Hello, I'm trying to authorize a user wallet from my app to Phanton iOS using Universal links. I managed to launch the app and I can see the authorizartion request. Although when I accept it, I'm getting

?errorCode=-32603&errorMessage=Something+went+wrong.

and according to the official docs this is an internal issue. This is my test implementation so far:

private func requestWalletAuthorization() {
        guard let keypair = try? NaclBox.keyPair() else { return }
        let publicKey = keypair.publicKey.map { String(format: "%02hhx", $0) }.joined()

        Task {
            guard var urlComponents = URLComponents(
                string: "https://phantom.app/ul/v1/connect"
            ) else {
                return
            }
            urlComponents.queryItems = [
                URLQueryItem(
                    name: "app_url",
                    value: "https://website.com/"
                ),
                URLQueryItem(
                    name: "dapp_encryption_public_key",
                    value: publicKey
                ),
                URLQueryItem(
                    name: "redirect_link",
                    value: "https://website.com/"
                )
            ]

           // result: https://phantom.app/ul/v1/connect?app_url=https://website.com/&dapp_encryption_public_key=xxxxxxx&redirect_link=https://website.com/
            await UIApplication.shared.open(urlComponents.url!)
        }
    }

You guys have any clue on what I'm doing wrong? Thank you in advance.

mejiagarcia commented 2 years ago

Nevermind, I was creating the publicKey incorrectly. I used https://github.com/keefertaylor/Base58Swift and solved the issue, now the universal link is responding correctly.