Skip to content

Commit

Permalink
Merge pull request #1172 from WalletConnect/feature/siwe-spec-change
Browse files Browse the repository at this point in the history
[Notify] SIWE Spec change
  • Loading branch information
flypaper0 authored Oct 11, 2023
2 parents 6cb2405 + 0f18520 commit c29b11e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 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, isLimited: Bool = false, onSign: @escaping SigningCallback) async throws {
try await identityService.register(account: account, domain: domain, isLimited: isLimited, onSign: onSign)
public func register(account: Account, domain: String, onSign: @escaping SigningCallback) async throws {
try await identityService.register(account: account, domain: domain, onSign: onSign)
subscriptionWatcher.setAccount(account)
}

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

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

private extension NotifyIdentityService {

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)."
}
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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,30 @@ 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 @@ -59,7 +79,8 @@ struct NotifyWatchSubscriptionsPayload: JWTClaimsCodable {
act: Claims.action,
iss: iss,
aud: notifyServerIdentityKey.did(variant: .ED25519),
sub: subscriptionAccount.did
sub: subscriptionAccount.did,
app: nil
)
}

Expand Down
3 changes: 1 addition & 2 deletions 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, isLimited: params.isLimited, onSign: onSign)
try await client.register(account: params.account, domain: params.domain, onSign: onSign)
try await respond(request: request)
}
}
Expand Down Expand Up @@ -92,7 +92,6 @@ 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 c29b11e

Please sign in to comment.