-
Notifications
You must be signed in to change notification settings - Fork 191
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
[Chat] sync chat sdk with kotlin implementation and add reject method #322
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8a47f9f
remove invite envelope
llbartekll 3739c4e
savepoint
llbartekll 61c00e6
add custom encoder
llbartekll 3ab42dc
fix chat encoding
llbartekll 4ab7d33
rename pubkey to publicKey in chat invite
llbartekll 8b00b2c
add reject method
llbartekll 7ca77e3
Merge branch 'develop' of github.com:WalletConnect/WalletConnectSwift…
llbartekll 4862d0e
fix build
llbartekll 0de54ce
sync messages with kotlin
llbartekll bb87e42
fix timestamp in message to miliseconds
llbartekll 46f0d60
comment out tests
llbartekll dbd9cce
remove print statement
llbartekll 14b8d1e
remove invite payload after accepting an invite
llbartekll 0ffedc8
apply PR comments
llbartekll 08b49ee
Merge branch 'develop' of github.com:WalletConnect/WalletConnectSwift…
llbartekll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
File renamed without changes.
File renamed without changes.
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,8 @@ | ||
|
||
import Foundation | ||
|
||
class LeaveService { | ||
func leave(topic: String) async 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 |
---|---|---|
|
@@ -42,7 +42,7 @@ class InvitationHandlingService { | |
|
||
let selfThreadPubKey = try kms.createX25519KeyPair() | ||
|
||
let inviteResponse = InviteResponse(pubKey: selfThreadPubKey.hexRepresentation) | ||
let inviteResponse = InviteResponse(publicKey: selfThreadPubKey.hexRepresentation) | ||
|
||
let response = JsonRpcResult.response(JSONRPCResponse<AnyCodable>(id: payload.request.id, result: AnyCodable(inviteResponse))) | ||
|
||
|
@@ -52,24 +52,43 @@ class InvitationHandlingService { | |
|
||
try await networkingInteractor.respond(topic: responseTopic, response: response) | ||
|
||
let threadAgreementKeys = try kms.performKeyAgreement(selfPublicKey: selfThreadPubKey, peerPublicKey: invite.pubKey) | ||
let threadAgreementKeys = try kms.performKeyAgreement(selfPublicKey: selfThreadPubKey, peerPublicKey: invite.publicKey) | ||
|
||
let threadTopic = threadAgreementKeys.derivedTopic() | ||
|
||
try kms.setSymmetricKey(threadAgreementKeys.sharedKey, for: threadTopic) | ||
|
||
try await networkingInteractor.subscribe(topic: threadTopic) | ||
|
||
logger.debug("Accepting an invite") | ||
logger.debug("Accepting an invite on topic: \(threadTopic)") | ||
|
||
// TODO - derive account | ||
let selfAccount = Account("eip155:56:0xe5EeF1368781911d265fDB6946613dA61915a501")! | ||
let thread = Thread(topic: threadTopic, selfAccount: selfAccount, peerAccount: invite.account) | ||
await threadsStore.add(thread) | ||
|
||
invitePayloadStore.delete(forKey: inviteId) | ||
|
||
onNewThread?(thread) | ||
} | ||
|
||
func reject(inviteId: String) async throws { | ||
|
||
guard let payload = try invitePayloadStore.get(key: inviteId) else { throw Error.inviteForIdNotFound } | ||
|
||
guard case .invite(let invite) = payload.request.params else {return} | ||
|
||
let responseTopic = try getInviteResponseTopic(payload, invite) | ||
|
||
//TODO - error not in specs yet | ||
let error = JSONRPCErrorResponse.Error(code: 0, message: "user rejected") | ||
let response = JsonRpcResult.error(JSONRPCErrorResponse(id: payload.request.id, error: error)) | ||
|
||
try await networkingInteractor.respond(topic: responseTopic, response: response) | ||
|
||
invitePayloadStore.delete(forKey: inviteId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gj, need to do the same for approve |
||
} | ||
|
||
private func setUpRequestHandling() { | ||
networkingInteractor.requestPublisher.sink { [unowned self] subscriptionPayload in | ||
switch subscriptionPayload.request.params { | ||
|
@@ -87,7 +106,7 @@ class InvitationHandlingService { | |
|
||
private func handleInvite(_ invite: Invite, _ payload: RequestSubscriptionPayload) throws { | ||
logger.debug("did receive an invite") | ||
invitePayloadStore.set(payload, forKey: invite.pubKey) | ||
invitePayloadStore.set(payload, forKey: invite.publicKey) | ||
onInvite?(invite) | ||
} | ||
|
||
|
@@ -101,7 +120,7 @@ class InvitationHandlingService { | |
|
||
let selfPubKey = try AgreementPublicKey(hex: selfPubKeyHex) | ||
|
||
let agreementKeysI = try kms.performKeyAgreement(selfPublicKey: selfPubKey, peerPublicKey: invite.pubKey) | ||
let agreementKeysI = try kms.performKeyAgreement(selfPublicKey: selfPubKey, peerPublicKey: invite.publicKey) | ||
|
||
// agreement keys already stored by serializer | ||
let responseTopic = agreementKeysI.derivedTopic() | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need to do that? Is it possible to avoid struct mutation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wc_chatMessage
does not contain topic but when we query messages from storage it is convenient to distinguish them by topic.maybe some storage improvement could allow to avoid this but instant sync with kotlin was a priority
will take this into consideration in next storage PR