@@ -13,6 +13,7 @@ import * as AppIdentityService from './services/app-identity.ts';
1313import * as ConnectionsService from './services/connections.ts' ;
1414import * as IdentityService from './services/identity.ts' ;
1515import * as InvitationsService from './services/invitations.ts' ;
16+ import * as PrivyAuthService from './services/privy-auth.ts' ;
1617import * as SpaceInboxService from './services/space-inbox.ts' ;
1718import * as SpacesService from './services/spaces.ts' ;
1819import * as UpdatesService from './services/updates.ts' ;
@@ -30,18 +31,34 @@ export const WebSocketLayer = HttpLayerRouter.add(
3031 const connectionsService = yield * ConnectionsService . ConnectionsService ;
3132 const accountInboxService = yield * AccountInboxService . AccountInboxService ;
3233 const spaceInboxService = yield * SpaceInboxService . SpaceInboxService ;
34+ const appIdentityService = yield * AppIdentityService . AppIdentityService ;
35+ const identityService = yield * IdentityService . IdentityService ;
36+ const privyAuthService = yield * PrivyAuthService . PrivyAuthService ;
3337 const responseMailbox = yield * Mailbox . make < Messages . ResponseMessage > ( ) ;
3438
3539 const searchParams = HttpServerRequest . searchParamsFromURL ( new URL ( request . url , 'http://localhost' ) ) ;
3640 const token = isArray ( searchParams . token ) ? searchParams . token [ 0 ] : searchParams . token ;
37-
38- if ( ! token ) {
41+ const privyIdentityToken = isArray ( searchParams [ 'privy-identity-token' ] )
42+ ? searchParams [ 'privy-identity-token' ] [ 0 ]
43+ : searchParams [ 'privy-identity-token' ] ;
44+ const privyAccountAddress = isArray ( searchParams [ 'account-address' ] )
45+ ? searchParams [ 'account-address' ] [ 0 ]
46+ : searchParams [ 'account-address' ] ;
47+
48+ if ( ! token && ( ! privyIdentityToken || ! privyAccountAddress ) ) {
3949 return yield * HttpServerResponse . empty ( { status : 400 } ) ;
4050 }
4151
42- const appIdentityService = yield * AppIdentityService . AppIdentityService ;
43- const identityService = yield * IdentityService . IdentityService ;
44- const { accountAddress, address } = yield * appIdentityService . getBySessionToken ( token ) . pipe ( Effect . orDie ) ;
52+ let accountAddress : string ;
53+ let address : string | undefined ;
54+ if ( privyIdentityToken && privyAccountAddress ) {
55+ yield * privyAuthService . authenticateRequest ( privyIdentityToken , privyAccountAddress ) . pipe ( Effect . orDie ) ;
56+ accountAddress = privyAccountAddress ;
57+ } else {
58+ const result = yield * appIdentityService . getBySessionToken ( token ) . pipe ( Effect . orDie ) ;
59+ accountAddress = result . accountAddress ;
60+ address = result . address ;
61+ }
4562
4663 // Register this connection
4764 const connectionId = yield * connectionsService . registerConnection ( {
@@ -60,14 +77,17 @@ export const WebSocketLayer = HttpLayerRouter.add(
6077 const request = yield * decodeRequestMessage ( json ) ;
6178 switch ( request . type ) {
6279 case 'list-spaces' : {
63- const spaces = yield * spacesService . listByAppIdentity ( address ) ;
80+ const spaces = yield * spacesService . listByAppIdentityOrAccount ( {
81+ appIdentityAddress : address ,
82+ accountAddress,
83+ } ) ;
6484 const outgoingMessage : Messages . ResponseListSpaces = { type : 'list-spaces' , spaces : spaces } ;
6585 // TODO: fix Messages.serialize
6686 yield * responseMailbox . offer ( Messages . serializeV2 ( outgoingMessage ) ) ;
6787 break ;
6888 }
6989 case 'list-invitations' : {
70- const invitations = yield * invitationsService . listByAppIdentity ( accountAddress ) ;
90+ const invitations = yield * invitationsService . listByAccountAddress ( accountAddress ) ;
7191 const outgoingMessage : Messages . ResponseListInvitations = {
7292 type : 'list-invitations' ,
7393 invitations,
@@ -215,7 +235,7 @@ export const WebSocketLayer = HttpLayerRouter.add(
215235 const inviteeAccountAddress = request . event . transaction . inviteeAccountAddress ;
216236
217237 // Get the updated invitation list for the invitee
218- const invitations = yield * invitationsService . listByAppIdentity ( inviteeAccountAddress ) ;
238+ const invitations = yield * invitationsService . listByAccountAddress ( inviteeAccountAddress ) ;
219239 const invitationMessage : Messages . ResponseListInvitations = {
220240 type : 'list-invitations' ,
221241 invitations,
@@ -432,5 +452,6 @@ export const WebSocketLayer = HttpLayerRouter.add(
432452 . pipe ( Effect . provide ( IdentityService . layer ) )
433453 . pipe ( Effect . provide ( UpdatesService . layer ) )
434454 . pipe ( Effect . provide ( AccountInboxService . layer ) )
435- . pipe ( Effect . provide ( SpaceInboxService . layer ) ) ,
455+ . pipe ( Effect . provide ( SpaceInboxService . layer ) )
456+ . pipe ( Effect . provide ( PrivyAuthService . layer ) ) ,
436457) ;
0 commit comments