-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #412 from WalletConnect/develop
v0.9.3-rc.0
- Loading branch information
Showing
27 changed files
with
319 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Combine | ||
import Foundation | ||
import WalletConnectUtils | ||
import JSONRPC | ||
|
||
class AuthRespondSubscriber { | ||
private let networkingInteractor: NetworkInteracting | ||
private let logger: ConsoleLogging | ||
private let rpcHistory: RPCHistory | ||
private var publishers = [AnyCancellable]() | ||
var onResponse: ((_ id: RPCID, _ cacao: Cacao) -> Void)? | ||
|
||
init(networkingInteractor: NetworkInteracting, | ||
logger: ConsoleLogging, | ||
rpcHistory: RPCHistory) { | ||
self.networkingInteractor = networkingInteractor | ||
self.logger = logger | ||
self.rpcHistory = rpcHistory | ||
subscribeForResponse() | ||
} | ||
|
||
private func subscribeForResponse() { | ||
networkingInteractor.responsePublisher.sink { [unowned self] subscriptionPayload in | ||
guard let request = rpcHistory.get(recordId: subscriptionPayload.request.id!)?.request, | ||
request.method == "wc_authRequest" else { return } | ||
networkingInteractor.unsubscribe(topic: subscriptionPayload.topic) | ||
guard let cacao = try? subscriptionPayload.request.result?.get(Cacao.self) else { | ||
logger.debug("Malformed auth response params") | ||
return | ||
} | ||
do { | ||
try CacaoSignatureVerifier().verifySignature(cacao) | ||
onResponse?(subscriptionPayload.request.id!, cacao) | ||
} catch { | ||
logger.debug("Received response with invalid signature") | ||
} | ||
}.store(in: &publishers) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Foundation | ||
|
||
protocol CacaoSignatureVerifying { | ||
func verifySignature(_ cacao: Cacao) throws | ||
} | ||
|
||
class CacaoSignatureVerifier: CacaoSignatureVerifying { | ||
enum Errors: Error { | ||
case signatureInvalid | ||
} | ||
|
||
func verifySignature(_ cacao: Cacao) throws { | ||
fatalError("not implemented") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,76 @@ | ||
import Foundation | ||
import WalletConnectUtils | ||
|
||
protocol SIWEMessageFormatting { | ||
func formatMessage(from request: AuthRequestParams) throws -> String | ||
func formatMessage(from authPayload: AuthPayload, address: String) -> String | ||
} | ||
|
||
struct SIWEMessageFormatter: SIWEMessageFormatting { | ||
func formatMessage(from request: AuthRequestParams) throws -> String { | ||
fatalError("not implemented") | ||
func formatMessage(from authPayload: AuthPayload, address: String) -> String { | ||
SIWEMessage(domain: authPayload.domain, | ||
uri: authPayload.aud, | ||
address: address, | ||
version: authPayload.version, | ||
nonce: authPayload.nonce, | ||
chainId: authPayload.chainId, | ||
iat: authPayload.iat, | ||
nbf: authPayload.nbf, | ||
exp: authPayload.exp, | ||
statement: authPayload.statement, | ||
requestId: authPayload.requestId, | ||
resources: authPayload.resources).formatted | ||
} | ||
} | ||
|
||
fileprivate struct SIWEMessage: Equatable { | ||
let domain: String | ||
let uri: String //aud | ||
let address: String | ||
let version: Int | ||
let nonce: String | ||
let chainId: String | ||
let iat: String | ||
let nbf: String? | ||
let exp: String? | ||
let statement: String? | ||
let requestId: String? | ||
let resources: [String]? | ||
|
||
var formatted: String { | ||
return """ | ||
\(domain) wants you to sign in with your Ethereum account: | ||
\(address) | ||
\(statementLine) | ||
URI: \(uri) | ||
Version: \(version) | ||
Chain ID: \(chainId) | ||
Nonce: \(nonce) | ||
Issued At: \(iat)\(expLine)\(nbfLine)\(requestIdLine)\(resourcesSection) | ||
""" | ||
} | ||
|
||
var expLine: String { | ||
guard let exp = exp else { return "" } | ||
return "\nExpiration Time: \(exp)" | ||
} | ||
|
||
var statementLine: String { | ||
guard let statement = statement else { return "" } | ||
return "\n\(statement)\n" | ||
} | ||
|
||
var nbfLine: String { | ||
guard let nbf = nbf else { return "" } | ||
return "\nNot Before: \(nbf)" | ||
} | ||
|
||
var requestIdLine: String { | ||
guard let requestId = requestId else { return "" } | ||
return "\nRequest ID: \(requestId)" | ||
} | ||
|
||
var resourcesSection: String { | ||
guard let resources = resources else { return "" } | ||
return resources.reduce("\nResources:") { $0 + "\n- \($1)" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import Foundation | ||
import JSONRPC | ||
|
||
struct RequestSubscriptionPayload: Codable { | ||
let id: Int64 | ||
struct RequestSubscriptionPayload: Codable, Equatable { | ||
let topic: String | ||
let request: RPCRequest | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Foundation | ||
import JSONRPC | ||
|
||
struct ResponseSubscriptionPayload: Codable, Equatable { | ||
let topic: String | ||
let request: RPCResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.