Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Notify] Watch subscription response not delivered fix #1134

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Example/WalletApp/ApplicationLayer/ConfigurationService.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Foundation
import UIKit
import WalletConnectNetworking
import WalletConnectNotify
import Web3Wallet
Expand Down Expand Up @@ -26,7 +26,15 @@ final class ConfigurationService {

Notify.instance.setLogging(level: .debug)

Task { try await Notify.instance.register(account: importAccount.account, domain: "com.walletconnect", onSign: importAccount.onSign) }
Task {
do {
try await Notify.instance.register(account: importAccount.account, domain: "com.walletconnect", onSign: importAccount.onSign)
} catch {
DispatchQueue.main.async {
UIApplication.currentWindow.rootViewController?.showAlert(title: "Register error", error: error)
}
}
}

if let clientId = try? Networking.interactor.getClientId() {
LoggingService.instance.setUpUser(account: importAccount.account.absoluteString, clientId: clientId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ extension UIViewController {
navigationController.navigationBar.prefersLargeTitles = true
return navigationController
}

func showAlert(title: String, error: Error) {
let alert = UIAlertController(title: title, message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(alert, animated: true, completion: nil)
}
}

extension UIApplication {
Expand Down
33 changes: 14 additions & 19 deletions Sources/WalletConnectJWT/JWT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import Foundation

struct JWT<JWTClaims: JWTEncodable>: Codable, Equatable {

var header: JWTHeader
var claims: JWTClaims
var signature: String?
let header: JWTHeader
let claims: JWTClaims
let signature: String
let string: String

init(header: JWTHeader = JWTHeader(), claims: JWTClaims) {
self.header = header
init(claims: JWTClaims, signer: JWTSigning) throws {
self.header = JWTHeader(alg: signer.alg)
self.claims = claims

let headerString = try header.encode()
let claimsString = try claims.encode()
let signature = try signer.sign(header: headerString, claims: claimsString)

self.signature = signature
self.string = [headerString, claimsString, signature].joined(separator: ".")
}

init(string: String) throws {
Expand All @@ -19,19 +27,6 @@ struct JWT<JWTClaims: JWTEncodable>: Codable, Equatable {
self.header = try JWTHeader.decode(from: components[0])
self.claims = try JWTClaims.decode(from: components[1])
self.signature = components[2]
}

mutating func sign(using jwtSigner: JWTSigning) throws {
header.alg = jwtSigner.alg
let headerString = try header.encode()
let claimsString = try claims.encode()
self.signature = try jwtSigner.sign(header: headerString, claims: claimsString)
}

func encoded() throws -> String {
guard let signature = signature else { throw JWTError.jwtNotSigned }
let headerString = try header.encode()
let claimsString = try claims.encode()
return [headerString, claimsString, signature].joined(separator: ".")
self.string = string
}
}
6 changes: 2 additions & 4 deletions Sources/WalletConnectJWT/JWTDecodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ extension JWTClaimsCodable {

public func signAndCreateWrapper(keyPair: SigningPrivateKey) throws -> Wrapper {
let claims = try encode(iss: keyPair.publicKey.did)
var jwt = JWT(claims: claims)
try jwt.sign(using: EdDSASigner(keyPair))
let jwtString = try jwt.encoded()
return Wrapper(jwtString: jwtString)
let jwt = try JWT(claims: claims, signer: EdDSASigner(keyPair))
return Wrapper(jwtString: jwt.string)
}

public func defaultIat() -> UInt64 {
Expand Down