@@ -2,14 +2,16 @@ import { CreateSpace } from '@/components/create-space';
22import { Button } from '@/components/ui/button' ;
33import { useSpaces } from '@/hooks/use-spaces' ;
44import { Connect , type Identity , Key , type Messages , StoreConnect , Utils } from '@graphprotocol/hypergraph' ;
5+ import { GEOGENESIS , GEO_TESTNET } from '@graphprotocol/hypergraph/connect/smart-account' ;
56import { useIdentityToken , usePrivy , useWallets } from '@privy-io/react-auth' ;
67import { createFileRoute } from '@tanstack/react-router' ;
78import { createStore } from '@xstate/store' ;
89import { useSelector } from '@xstate/store/react' ;
910import { Effect , Schema } from 'effect' ;
1011import { useEffect } from 'react' ;
1112import { createWalletClient , custom } from 'viem' ;
12- import { mainnet } from 'viem/chains' ;
13+
14+ const CHAIN = import . meta. env . VITE_HYPERGRAPH_CHAIN === 'geogenesis' ? GEOGENESIS : GEO_TESTNET ;
1315
1416type AuthenticateSearch = {
1517 data : unknown ;
@@ -150,6 +152,7 @@ function AuthenticateComponent() {
150152 {
151153 headers : {
152154 'privy-id-token' : identityToken ,
155+ 'account-address' : accountAddress ,
153156 'Content-Type' : 'application/json' ,
154157 } ,
155158 } ,
@@ -261,6 +264,7 @@ function AuthenticateComponent() {
261264 const message : Messages . RequestConnectAddAppIdentityToSpaces = {
262265 type : 'connect-add-app-identity-to-spaces' ,
263266 appIdentityAddress : appIdentity . address ,
267+ accountAddress,
264268 spacesInput,
265269 } ;
266270
@@ -284,6 +288,7 @@ function AuthenticateComponent() {
284288 appIdentityAddress : appIdentity . address ,
285289 appIdentityAddressPrivateKey : appIdentity . addressPrivateKey ,
286290 accountAddress : accountAddress ,
291+ permissionId : appIdentity . permissionId ,
287292 encryptionPrivateKey : appIdentity . encryptionPrivateKey ,
288293 signaturePrivateKey : appIdentity . signaturePrivateKey ,
289294 signaturePublicKey : appIdentity . signaturePublicKey ,
@@ -311,7 +316,7 @@ function AuthenticateComponent() {
311316 try {
312317 const privyProvider = await embeddedWallet . getEthereumProvider ( ) ;
313318 const walletClient = createWalletClient ( {
314- chain : mainnet ,
319+ chain : CHAIN ,
315320 transport : custom ( privyProvider ) ,
316321 } ) ;
317322
@@ -331,18 +336,33 @@ function AuthenticateComponent() {
331336 } ;
332337
333338 const newAppIdentity = Connect . createAppIdentity ( ) ;
339+ // TODO: add spaces and additional actions
340+ const permissionId = await Connect . createSmartSession (
341+ walletClient ,
342+ accountAddress ,
343+ newAppIdentity . addressPrivateKey ,
344+ CHAIN ,
345+ import . meta. env . VITE_HYPERGRAPH_RPC_URL ,
346+ {
347+ allowCreateSpace : true ,
348+ spaces : [ ] ,
349+ additionalActions : [ ] ,
350+ } ,
351+ ) ;
352+
334353 const { ciphertext, nonce } = await Connect . encryptAppIdentity (
335354 signer ,
336- accountAddress ,
337355 newAppIdentity . address ,
338356 newAppIdentity . addressPrivateKey ,
357+ permissionId ,
339358 keys ,
340359 ) ;
341360 const { accountProof, keyProof } = await Connect . proveIdentityOwnership ( signer , accountAddress , keys ) ;
342361
343362 const message : Messages . RequestConnectCreateAppIdentity = {
344363 appId : state . appInfo . appId ,
345364 address : newAppIdentity . address ,
365+ accountAddress,
346366 signaturePublicKey : newAppIdentity . signaturePublicKey ,
347367 encryptionPublicKey : newAppIdentity . encryptionPublicKey ,
348368 ciphertext,
@@ -372,6 +392,7 @@ function AuthenticateComponent() {
372392 signaturePublicKey : newAppIdentity . signaturePublicKey ,
373393 sessionToken : appIdentityResponse . appIdentity . sessionToken ,
374394 sessionTokenExpires : new Date ( appIdentityResponse . appIdentity . sessionTokenExpires ) ,
395+ permissionId,
375396 } ,
376397 appInfo : state . appInfo ,
377398 } ) ;
@@ -392,7 +413,7 @@ function AuthenticateComponent() {
392413
393414 const privyProvider = await embeddedWallet . getEthereumProvider ( ) ;
394415 const walletClient = createWalletClient ( {
395- chain : mainnet ,
416+ chain : CHAIN ,
396417 transport : custom ( privyProvider ) ,
397418 } ) ;
398419
@@ -413,7 +434,6 @@ function AuthenticateComponent() {
413434
414435 const decryptedIdentity = await Connect . decryptAppIdentity (
415436 signer ,
416- state . appIdentityResponse . accountAddress ,
417437 state . appIdentityResponse . ciphertext ,
418438 state . appIdentityResponse . nonce ,
419439 ) ;
@@ -422,7 +442,8 @@ function AuthenticateComponent() {
422442 appIdentity : {
423443 address : decryptedIdentity . address ,
424444 addressPrivateKey : decryptedIdentity . addressPrivateKey ,
425- accountAddress : decryptedIdentity . accountAddress ,
445+ accountAddress : state . appIdentityResponse . accountAddress ,
446+ permissionId : decryptedIdentity . permissionId ,
426447 encryptionPrivateKey : decryptedIdentity . encryptionPrivateKey ,
427448 signaturePrivateKey : decryptedIdentity . signaturePrivateKey ,
428449 encryptionPublicKey : decryptedIdentity . encryptionPublicKey ,
0 commit comments