Skip to content

Commit

Permalink
Revert "Merge pull request #1172 from WalletConnect/feature/siwe-spec…
Browse files Browse the repository at this point in the history
…-change"

This reverts commit c29b11e, reversing
changes made to 6cb2405.
  • Loading branch information
flypaper0 committed Oct 12, 2023
1 parent 476c0fe commit 50b99f7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Sources/WalletConnectNotify/Client/Wallet/NotifyClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public class NotifyClient {
self.subscriptionWatcher = subscriptionWatcher
}

public func register(account: Account, domain: String, onSign: @escaping SigningCallback) async throws {
try await identityService.register(account: account, domain: domain, onSign: onSign)
public func register(account: Account, domain: String, isLimited: Bool = false, onSign: @escaping SigningCallback) async throws {
try await identityService.register(account: account, domain: domain, isLimited: isLimited, onSign: onSign)
subscriptionWatcher.setAccount(account)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ final class NotifyIdentityService {
self.logger = logger
}

public func register(account: Account, domain: String, onSign: @escaping SigningCallback) async throws {
public func register(account: Account, domain: String, isLimited: Bool, onSign: @escaping SigningCallback) async throws {
let statement = makeStatement(isLimited: isLimited, domain: domain, keyserverHost: keyserverURL.host!)
let pubKey = try await identityClient.register(account: account,
domain: domain,
statement: makeStatement(),
statement: statement,
resources: [keyserverURL.absoluteString],
onSign: onSign)
logger.debug("Did register an account: \(account)")
Expand All @@ -28,7 +29,12 @@ final class NotifyIdentityService {

private extension NotifyIdentityService {

func makeStatement() -> String {
return "I further authorize this app to send and receive messages on my behalf using my WalletConnect identity. Read more at https://walletconnect.com/identity"
func makeStatement(isLimited: Bool, domain: String, keyserverHost: String) -> String {
switch isLimited {
case true:
return "I further authorize this DAPP to send and receive messages on my behalf for this domain and manage my identity at \(keyserverHost)."
case false:
return "I further authorize this WALLET to send and receive messages on my behalf for ALL domains and manage my identity at \(keyserverHost)."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,10 @@ struct NotifyWatchSubscriptionsPayload: JWTClaimsCodable {
let aud: String
/// Blockchain account that notify subscription has been proposed for -`did:pkh`
let sub: String
/// Dapp domain url
let app: String?

static var action: String? {
return "notify_watch_subscriptions"
}

// Note: - Overriding `encode(to encoder: Encoder)` implementation to force null app encoding

enum CodingKeys: CodingKey {
case iat, exp, ksu, act, iss, aud, sub, app
}

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: NotifyWatchSubscriptionsPayload.Claims.CodingKeys.self)
try container.encode(self.iat, forKey: NotifyWatchSubscriptionsPayload.Claims.CodingKeys.iat)
try container.encode(self.exp, forKey: NotifyWatchSubscriptionsPayload.Claims.CodingKeys.exp)
try container.encode(self.ksu, forKey: NotifyWatchSubscriptionsPayload.Claims.CodingKeys.ksu)
try container.encodeIfPresent(self.act, forKey: NotifyWatchSubscriptionsPayload.Claims.CodingKeys.act)
try container.encode(self.iss, forKey: NotifyWatchSubscriptionsPayload.Claims.CodingKeys.iss)
try container.encode(self.aud, forKey: NotifyWatchSubscriptionsPayload.Claims.CodingKeys.aud)
try container.encode(self.sub, forKey: NotifyWatchSubscriptionsPayload.Claims.CodingKeys.sub)
try container.encode(self.app, forKey: NotifyWatchSubscriptionsPayload.Claims.CodingKeys.app)
}
}

struct Wrapper: JWTWrapper {
Expand Down Expand Up @@ -79,8 +59,7 @@ struct NotifyWatchSubscriptionsPayload: JWTClaimsCodable {
act: Claims.action,
iss: iss,
aud: notifyServerIdentityKey.did(variant: .ED25519),
sub: subscriptionAccount.did,
app: nil
sub: subscriptionAccount.did
)
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/Web3Inbox/NotifyClientProxy/NotifyClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class NotifyClientProxy {
try await respond(request: request)
case .register:
let params = try parse(RegisterRequest.self, params: request.params)
try await client.register(account: params.account, domain: params.domain, onSign: onSign)
try await client.register(account: params.account, domain: params.domain, isLimited: params.isLimited, onSign: onSign)
try await respond(request: request)
}
}
Expand Down Expand Up @@ -92,6 +92,7 @@ private extension NotifyClientProxy {
struct RegisterRequest: Codable {
let account: Account
let domain: String
let isLimited: Bool
}

func parse<Request: Codable>(_ type: Request.Type, params: AnyCodable?) throws -> Request {
Expand Down

0 comments on commit 50b99f7

Please sign in to comment.