@@ -44,6 +44,8 @@ public class SocketClient: CommClient {
44
44
public var trackEvent : ( ( Event , [ String : Any ] ) -> Void ) ?
45
45
46
46
var requestJobs : [ RequestJob ] = [ ]
47
+
48
+ var connectRpc : String ?
47
49
48
50
public var useDeeplinks : Bool = true
49
51
@@ -52,12 +54,30 @@ public class SocketClient: CommClient {
52
54
}
53
55
54
56
var deeplinkUrl : String {
55
- " \( _deeplinkUrl) /connect?channelId= "
57
+ let originatorInfo = OriginatorInfo (
58
+ title: appMetadata? . name,
59
+ url: appMetadata? . url,
60
+ icon: appMetadata? . iconUrl ?? appMetadata? . base64Icon,
61
+ dappId: SDKInfo . bundleIdentifier,
62
+ platform: SDKInfo . platform,
63
+ apiVersion: SDKInfo . version
64
+ )
65
+ let originatorInfoBase64 = originatorInfo. toJsonString ( ) ? . base64Encode ( ) ?? " "
66
+ let rpcBase64 : String ? = connectRpc? . base64Encode ( ) ?? nil
67
+
68
+ var deeplink = " \( _deeplinkUrl) /connect?channelId= "
56
69
+ channelId
57
70
+ " &comm=socket "
58
71
+ " &pubkey= "
59
72
+ keyExchange. pubkey
60
73
+ " &v=2 "
74
+ + " &originatorInfo= \( originatorInfoBase64) "
75
+
76
+ if let requestBase64 = rpcBase64 {
77
+ deeplink += " &rpc= \( requestBase64) "
78
+ connectRpc = nil // reset rpc request
79
+ }
80
+ return deeplink
61
81
}
62
82
63
83
private var isV2Protocol : Bool = false
@@ -90,6 +110,7 @@ public class SocketClient: CommClient {
90
110
91
111
public func connect( with request: String ? ) {
92
112
if channel. isConnected { return }
113
+ self . connectRpc = request
93
114
94
115
setupClient ( )
95
116
if isReconnection {
@@ -112,6 +133,7 @@ public class SocketClient: CommClient {
112
133
session. clear ( )
113
134
disconnect ( )
114
135
keyExchange. reset ( )
136
+ channel. emit ( ClientEvent . terminate, [ " channelId " : channelId, " clientType " : " dapp " ] )
115
137
}
116
138
117
139
private func initiateKeyExchange( ) {
@@ -201,11 +223,13 @@ extension SocketClient {
201
223
channel. on ( ClientEvent . config ( on: channelId) ) { [ weak self] data in
202
224
guard
203
225
let self = self ,
204
- let message = data. first as? [ String : Bool ] ,
205
- let persistence = message [ " persistence " ]
226
+ let message = data. first as? [ String : Any ] ,
227
+ let persistence = message [ " persistence " ] as? Bool ,
228
+ let walletKey = message [ " walletKey " ] as? String
206
229
else { return }
207
230
208
231
isV2Protocol = persistence
232
+ keyExchange. setTheirPublicKey ( walletKey)
209
233
210
234
if isV2Protocol {
211
235
isReady = true
@@ -315,6 +339,7 @@ extension SocketClient {
315
339
}
316
340
317
341
func handleMessage( _ msg: [ String : Any ] ) {
342
+
318
343
if isKeyExchangeMessage ( msg) {
319
344
handleReceiveKeyExchange ( msg)
320
345
return
@@ -376,6 +401,9 @@ extension SocketClient {
376
401
Logging . log ( " Received wallet info " )
377
402
isReady = true
378
403
} else if let data = json [ " data " ] as? [ String : Any ] {
404
+ if let walletKey = data [ " walletKey " ] as? String {
405
+ keyExchange. setTheirPublicKey ( walletKey)
406
+ }
379
407
handleResponse ? ( data)
380
408
}
381
409
}
0 commit comments