Skip to content

Commit

Permalink
Merge pull request #1394 from WalletConnect/feat/rejection_tags
Browse files Browse the repository at this point in the history
feat: rejection tags
  • Loading branch information
jakubuid authored May 15, 2024
2 parents fb5ea1c + 64f935b commit ceb3593
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ enum class Tags(val id: Int) {
PAIRING_PING_RESPONSE(1003),

SESSION_PROPOSE(1100),
SESSION_PROPOSE_RESPONSE(1101),
SESSION_PROPOSE_RESPONSE_APPROVE(1101),
SESSION_PROPOSE_RESPONSE_REJECT(1120),
SESSION_PROPOSE_RESPONSE_AUTO_REJECT(1121),

SESSION_SETTLE(1102),
SESSION_SETTLE_RESPONSE(1103),
Expand All @@ -34,7 +36,9 @@ enum class Tags(val id: Int) {
SESSION_PING_RESPONSE(1115),

SESSION_AUTHENTICATE(1116),
SESSION_AUTHENTICATE_RESPONSE(1117),
SESSION_AUTHENTICATE_RESPONSE_APPROVE(1117),
SESSION_AUTHENTICATE_RESPONSE_REJECT(1118),
SESSION_AUTHENTICATE_RESPONSE_AUTO_REJECT(1119),

CHAT_INVITE(2000),
CHAT_INVITE_RESPONSE(2001),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ internal class ApproveSessionAuthenticateUseCase(
val symmetricKey: SymmetricKey = crypto.generateSymmetricKeyFromKeyAgreement(senderPublicKey, receiverPublicKey)
val responseTopic: Topic = crypto.getTopicFromKey(receiverPublicKey)
val sessionTopic = crypto.getTopicFromKey(symmetricKey)
val irnParams = IrnParams(Tags.SESSION_AUTHENTICATE_RESPONSE, Ttl(dayInSeconds))
val irnParams = IrnParams(Tags.SESSION_AUTHENTICATE_RESPONSE_APPROVE, Ttl(dayInSeconds))

if (cacaos.find { cacao -> !cacaoVerifier.verify(cacao) } != null) {
logger.error("Invalid Cacao for Session Authenticate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ internal class ApproveSessionUseCase(
val selfPublicKey: PublicKey = crypto.generateAndStoreX25519KeyPair()
val sessionTopic = crypto.generateTopicFromKeyAgreement(selfPublicKey, PublicKey(proposerPublicKey))
val approvalParams = proposal.toSessionApproveParams(selfPublicKey)
val irnParams = IrnParams(Tags.SESSION_PROPOSE_RESPONSE, Ttl(fiveMinutesInSeconds))
val irnParams = IrnParams(Tags.SESSION_PROPOSE_RESPONSE_APPROVE, Ttl(fiveMinutesInSeconds))
logger.log("Subscribing to session topic: $sessionTopic")
jsonRpcInteractor.subscribe(sessionTopic,
onSuccess = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal class RejectSessionAuthenticateUseCase(
val responseTopic: Topic = crypto.getTopicFromKey(receiverPublicKey)

crypto.setKey(symmetricKey, responseTopic.value)
val irnParams = IrnParams(Tags.SESSION_AUTHENTICATE_RESPONSE, Ttl(dayInSeconds), false)
val irnParams = IrnParams(Tags.SESSION_AUTHENTICATE_RESPONSE_REJECT, Ttl(dayInSeconds), false)

logger.log("Sending Session Authenticate Reject on topic: $responseTopic")
jsonRpcInteractor.publishJsonRpcResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class RejectSessionUseCase(
jsonRpcInteractor.respondWithError(
proposal.toSessionProposeRequest(),
PeerError.EIP1193.UserRejectedRequest(reason),
IrnParams(Tags.SESSION_PROPOSE_RESPONSE, Ttl(fiveMinutesInSeconds)),
IrnParams(Tags.SESSION_PROPOSE_RESPONSE_REJECT, Ttl(fiveMinutesInSeconds)),
onSuccess = {
logger.log("Session rejection sent successfully, topic: ${proposal.pairingTopic.value}")
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class OnSessionAuthenticateUseCase(
val events: SharedFlow<EngineEvent> = _events.asSharedFlow()

suspend operator fun invoke(request: WCRequest, authenticateSessionParams: SignParams.SessionAuthenticateParams) = supervisorScope {
val irnParams = IrnParams(Tags.SESSION_AUTHENTICATE_RESPONSE, Ttl(dayInSeconds))
val irnParams = IrnParams(Tags.SESSION_AUTHENTICATE_RESPONSE_AUTO_REJECT, Ttl(dayInSeconds))
logger.log("Received session authenticate: ${request.topic}")
try {
if (Expiry(authenticateSessionParams.expiryTimestamp).isExpired()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class OnSessionProposalUseCase(
private val isAuthenticateEnabled: Boolean by lazy { wcKoinApp.koin.get(named(AndroidCommonDITags.ENABLE_AUTHENTICATE)) }

suspend operator fun invoke(request: WCRequest, payloadParams: SignParams.SessionProposeParams) = supervisorScope {
val irnParams = IrnParams(Tags.SESSION_PROPOSE_RESPONSE, Ttl(fiveMinutesInSeconds))
val irnParams = IrnParams(Tags.SESSION_PROPOSE_RESPONSE_AUTO_REJECT, Ttl(fiveMinutesInSeconds))
try {
if (isSessionAuthenticateImplemented(request)) {
logger.error("Session proposal received error: pairing supports authenticated sessions")
Expand Down

0 comments on commit ceb3593

Please sign in to comment.