@@ -16,7 +16,9 @@ class MatchMakerClient extends EventEmitter {
1616
1717 super ( )
1818
19+
1920 this . contacts = contacts
21+ this . sessionKey = null
2022 this . identity = identity
2123 this . wsParty = null
2224 this . restParty = null
@@ -47,9 +49,7 @@ class MatchMakerClient extends EventEmitter {
4749
4850
4951 async start ( ) {
50- /*
51- *
52- */
52+ this . sessionKey = await dataparty_crypto . Identity . fromRandomSeed ( { id :'ephemeral-session-key' } )
5353
5454 if ( ! this . restParty ) {
5555 let config = new MemoryConfig ( {
@@ -65,7 +65,7 @@ class MatchMakerClient extends EventEmitter {
6565 config
6666 } )
6767
68- if ( this . identity ) { await this . restParty . setIdentity ( this . identity ) }
68+ await this . restParty . setIdentity ( this . sessionKey )
6969
7070 debug ( 'starting restParty' )
7171 await this . restParty . start ( )
@@ -102,7 +102,7 @@ class MatchMakerClient extends EventEmitter {
102102
103103 this . invitesRx = new this . wsParty . ROSLIB . Topic ( {
104104 ros : this . wsParty . comms . ros ,
105- name : '/invites/' + encodeURIComponent ( this . restParty . identity . key . hash ) + '/rx' ,
105+ name : '/invites/' + encodeURIComponent ( this . identity . key . hash ) + '/rx' ,
106106 messageType : 'Object'
107107 } )
108108
@@ -111,7 +111,7 @@ class MatchMakerClient extends EventEmitter {
111111
112112 this . invitesTx = new this . wsParty . ROSLIB . Topic ( {
113113 ros : this . wsParty . comms . ros ,
114- name : '/invites/' + encodeURIComponent ( this . restParty . identity . key . hash ) + '/tx' ,
114+ name : '/invites/' + encodeURIComponent ( this . identity . key . hash ) + '/tx' ,
115115 messageType : 'Object'
116116 } )
117117
@@ -161,13 +161,59 @@ class MatchMakerClient extends EventEmitter {
161161 }
162162 }
163163
164+
165+ /*
166+
167+ annoucement: {
168+ created: {
169+ type: Number,
170+ required: true
171+ },
172+ expiry: {
173+ type: Number,
174+ index: true,
175+ required: true
176+ },
177+ sessionKey: PublicKeySchema(true),
178+ actorKey: PublicKeySchema(false)
179+ },
180+ trust: {
181+ actorSig: {required: true, type: String}, //! base64 of BSON signature
182+ sessionSig: {required: true, type: String} //! base64 of BSON signature
183+ }
184+ }
185+
186+ */
187+
188+
164189 async announcePublicKeys ( ) {
165190 const announceData = {
166- type : this . restParty . identity . key . type ,
167- hash : this . restParty . identity . key . hash ,
168- public : this . restParty . identity . key . public
191+ annoucement : {
192+ created : Date . now ( ) ,
193+ expiry : Date . now ( ) + 24 * 60 * 60 * 1000 , //! Set session expiry to 24hr from now
194+ sessionKey : {
195+ type : this . sessionKey . key . type ,
196+ hash : this . sessionKey . key . hash ,
197+ public : this . sessionKey . key . public
198+ } ,
199+ actorKey : {
200+ type : this . identity . key . type ,
201+ hash : this . identity . key . hash ,
202+ public : this . identity . key . public
203+ }
204+ } ,
205+ trust : {
206+ actorSig : null ,
207+ sessionSig : null
208+ }
169209 }
170210
211+ const actorSigMsg = await this . identity . sign ( announceData . annoucement , true )
212+ const sessionSigMsg = await this . sessionKey . sign ( announceData . annoucement , true )
213+
214+ announceData . trust . actorSig = dataparty_crypto . Routines . Utils . base64 . encode ( actorSigMsg . sig )
215+ announceData . trust . sessionSig = dataparty_crypto . Routines . Utils . base64 . encode ( sessionSigMsg . sig )
216+
171217 debug ( 'announcePublicKeys' , announceData )
172218
173219 const announceResult = await this . restParty . comms . call ( 'key/announce' , announceData , {
@@ -181,8 +227,8 @@ class MatchMakerClient extends EventEmitter {
181227 async lookupPublicKey ( hash ) {
182228 debug ( 'lookupPublicKey - hash:' , hash )
183229
184- if ( hash == this . restParty . identity . key . hash ) {
185- return this . restParty . identity
230+ if ( hash == this . identity . key . hash ) {
231+ return this . identity
186232 }
187233
188234 if ( this . contacts ) {
@@ -229,7 +275,7 @@ class MatchMakerClient extends EventEmitter {
229275 service : service ? service : '@dataparty/video-chat' ,
230276 role : role ? role : 'client' ,
231277 timestamp : ( new Date ( ) ) . getTime ( ) ,
232- from : this . wsParty . identity . key . hash ,
278+ from : this . identity . key . hash ,
233279 to : toIdentity . key . hash ,
234280 session : session ? session : Math . random ( ) . toString ( 36 ) . slice ( 2 ) ,
235281 info : info ? info : {
@@ -238,13 +284,13 @@ class MatchMakerClient extends EventEmitter {
238284 }
239285 }
240286
241- const secureInvite = await this . wsParty . privateIdentity . encrypt ( invitePayload , toIdentity )
287+ const secureInvite = await this . identity . encrypt ( invitePayload , toIdentity )
242288
243289 debug ( 'secure-invite' , secureInvite )
244290
245291 const invitePostData = {
246292 to : toIdentity . key . hash ,
247- from : this . wsParty . identity . key . hash ,
293+ from : this . identity . key . hash ,
248294 payload : JSON . stringify ( secureInvite . toJSON ( ) )
249295 }
250296
@@ -258,7 +304,7 @@ class MatchMakerClient extends EventEmitter {
258304
259305 if ( ! inviteDoc ) { return }
260306
261- let invite = new PeerInvite ( inviteResult . invite , toIdentity , this , this . restParty . identity )
307+ let invite = new PeerInvite ( inviteResult . invite , toIdentity , this , this . identity )
262308
263309 invite . payload = invitePayload
264310
@@ -270,10 +316,11 @@ class MatchMakerClient extends EventEmitter {
270316 }
271317
272318 async lookupInvites ( { createdAfter, type= 'to' , id, actorHash } ) {
273- let actor = this . wsParty . identity . key . hash
319+ let actor = this . identity . key . hash
274320
275321 const lookup = {
276- invite :id , actor :actorHash ? actorHash : this . restParty . identity . key . hash ,
322+ invite : id ,
323+ actor : actorHash ? actorHash : this . identity . key . hash ,
277324 createdAfter,
278325 type : ! type ? 'to' : type
279326 }
@@ -336,7 +383,7 @@ class MatchMakerClient extends EventEmitter {
336383 async setInviteState ( invite , newState ) {
337384
338385 debug ( 'setInviteState' )
339- let actor = this . restParty . identity . key . hash
386+ let actor = this . identity . key . hash
340387
341388 const inviteState = {
342389 invite : invite . inviteDoc . $meta . id ,
0 commit comments