@@ -16,6 +16,10 @@ import { createWalletClient, custom } from 'viem';
1616import { privateKeyToAccount } from 'viem/accounts' ;
1717
1818const CHAIN = import . meta. env . VITE_HYPERGRAPH_CHAIN === 'geogenesis' ? Connect . GEOGENESIS : Connect . GEO_TESTNET ;
19+ const API_URL =
20+ import . meta. env . VITE_HYPERGRAPH_CHAIN === 'geogenesis'
21+ ? `${ Graph . MAINNET_API_ORIGIN } /graphql`
22+ : `${ Graph . TESTNET_API_ORIGIN } /graphql` ;
1923
2024type AuthenticateSearch = {
2125 data : unknown ;
@@ -135,19 +139,14 @@ function AuthenticateComponent() {
135139 const accountAddress = useSelector ( StoreConnect . store , ( state ) => state . context . accountAddress ) ;
136140 const keys = useSelector ( StoreConnect . store , ( state ) => state . context . keys ) ;
137141
138- const { signMessage } = usePrivy ( ) ;
139142 const { wallets } = useWallets ( ) ;
140143 const embeddedWallet = wallets . find ( ( wallet ) => wallet . walletClientType === 'privy' ) || wallets [ 0 ] ;
141144
142145 const state = useSelector ( componentStore , ( state ) => state . context ) ;
143146 const [ selectedPrivateSpaces , setSelectedPrivateSpaces ] = useState < Set < string > > ( new Set ( ) ) ;
144147
145148 const { isPending : privateSpacesPending , error : privateSpacesError , data : privateSpacesData } = usePrivateSpaces ( ) ;
146- const {
147- isPending : publicSpacesPending ,
148- error : publicSpacesError ,
149- data : publicSpacesData ,
150- } = usePublicSpaces ( `${ Graph . TESTNET_API_ORIGIN } /graphql` ) ;
149+ const { data : publicSpacesData } = usePublicSpaces ( API_URL ) ;
151150
152151 useEffect ( ( ) => {
153152 const run = async ( ) => {
@@ -261,7 +260,7 @@ function AuthenticateComponent() {
261260 id : keyData . id ,
262261 ciphertext : Utils . bytesToHex ( keyBox . keyBoxCiphertext ) ,
263262 nonce : Utils . bytesToHex ( keyBox . keyBoxNonce ) ,
264- authorPublicKey : appIdentity . encryptionPublicKey ,
263+ authorPublicKey : keys . encryptionPublicKey ,
265264 accountAddress : accountAddress ,
266265 } ;
267266 } ) ;
@@ -334,21 +333,6 @@ function AuthenticateComponent() {
334333 transport : custom ( privyProvider ) ,
335334 } ) ;
336335
337- const signer : Identity . Signer = {
338- getAddress : async ( ) => {
339- const [ address ] = await walletClient . getAddresses ( ) ;
340- return address ;
341- } ,
342- signMessage : async ( message : string ) => {
343- if ( embeddedWallet . walletClientType === 'privy' ) {
344- const { signature } = await signMessage ( { message } ) ;
345- return signature ;
346- }
347- const [ address ] = await walletClient . getAddresses ( ) ;
348- return await walletClient . signMessage ( { account : address , message } ) ;
349- } ,
350- } ;
351-
352336 const newAppIdentity = Connect . createAppIdentity ( ) ;
353337
354338 console . log ( 'creating smart session' ) ;
@@ -389,28 +373,21 @@ function AuthenticateComponent() {
389373 } ) ;
390374
391375 console . log ( 'encrypting app identity' ) ;
392- const { ciphertext, nonce } = await Connect . encryptAppIdentity (
393- signer ,
394- newAppIdentity . address ,
395- newAppIdentity . addressPrivateKey ,
396- permissionId ,
397- keys ,
398- ) ;
376+ const { ciphertext } = await Connect . encryptAppIdentity ( { ...newAppIdentity , permissionId } , keys ) ;
399377 console . log ( 'proving ownership' ) ;
400378 const { accountProof, keyProof } = await Identity . proveIdentityOwnership (
401379 smartAccountClient ,
402380 accountAddress ,
403- keys ,
381+ newAppIdentity ,
404382 ) ;
405383
406384 const message : Messages . RequestConnectCreateAppIdentity = {
407385 appId : state . appInfo . appId ,
408386 address : newAppIdentity . address ,
409387 accountAddress,
410- signaturePublicKey : newAppIdentity . signaturePublicKey ,
411- encryptionPublicKey : newAppIdentity . encryptionPublicKey ,
388+ signaturePublicKey : keys . signaturePublicKey ,
389+ encryptionPublicKey : keys . encryptionPublicKey ,
412390 ciphertext,
413- nonce,
414391 accountProof,
415392 keyProof,
416393 } ;
@@ -424,14 +401,16 @@ function AuthenticateComponent() {
424401 body : JSON . stringify ( message ) ,
425402 } ) ;
426403 const appIdentityResponse = await response . json ( ) ;
404+ // TODO: All apps are essentially using the same keys, we should change to using
405+ // the newly created app identity keys, but that requires changing a lot of the verification logic in the server and HypergraphAppContext
427406 await encryptSpacesAndRedirect ( {
428407 accountAddress,
429408 appIdentity : {
430409 address : newAppIdentity . address ,
431410 addressPrivateKey : newAppIdentity . addressPrivateKey ,
432411 accountAddress,
433- encryptionPrivateKey : keys . encryptionPrivateKey ,
434- signaturePrivateKey : keys . signaturePrivateKey ,
412+ encryptionPrivateKey : newAppIdentity . encryptionPrivateKey ,
413+ signaturePrivateKey : newAppIdentity . signaturePrivateKey ,
435414 encryptionPublicKey : newAppIdentity . encryptionPublicKey ,
436415 signaturePublicKey : newAppIdentity . signaturePublicKey ,
437416 sessionToken : appIdentityResponse . appIdentity . sessionToken ,
@@ -451,48 +430,16 @@ function AuthenticateComponent() {
451430 } ;
452431
453432 const decryptAppIdentityAndRedirect = async ( ) => {
454- if ( ! state . appIdentityResponse ) {
433+ if ( ! state . appIdentityResponse || ! keys ) {
455434 return ;
456435 }
457436
458- const privyProvider = await embeddedWallet . getEthereumProvider ( ) ;
459- const walletClient = createWalletClient ( {
460- account : embeddedWallet . address as `0x${string } `,
461- chain : CHAIN ,
462- transport : custom ( privyProvider ) ,
463- } ) ;
464-
465- const signer : Identity . Signer = {
466- getAddress : async ( ) => {
467- const [ address ] = await walletClient . getAddresses ( ) ;
468- return address ;
469- } ,
470- signMessage : async ( message : string ) => {
471- if ( embeddedWallet . walletClientType === 'privy' ) {
472- const { signature } = await signMessage ( { message } ) ;
473- return signature ;
474- }
475- const [ address ] = await walletClient . getAddresses ( ) ;
476- return await walletClient . signMessage ( { account : address , message } ) ;
477- } ,
478- } ;
479-
480- const decryptedIdentity = await Connect . decryptAppIdentity (
481- signer ,
482- state . appIdentityResponse . ciphertext ,
483- state . appIdentityResponse . nonce ,
484- ) ;
437+ const decryptedIdentity = await Connect . decryptAppIdentity ( state . appIdentityResponse . ciphertext , keys ) ;
485438 await encryptSpacesAndRedirect ( {
486439 accountAddress : state . appIdentityResponse . accountAddress ,
487440 appIdentity : {
488- address : decryptedIdentity . address ,
489- addressPrivateKey : decryptedIdentity . addressPrivateKey ,
441+ ...decryptedIdentity ,
490442 accountAddress : state . appIdentityResponse . accountAddress ,
491- permissionId : decryptedIdentity . permissionId ,
492- encryptionPrivateKey : decryptedIdentity . encryptionPrivateKey ,
493- signaturePrivateKey : decryptedIdentity . signaturePrivateKey ,
494- encryptionPublicKey : decryptedIdentity . encryptionPublicKey ,
495- signaturePublicKey : decryptedIdentity . signaturePublicKey ,
496443 sessionToken : state . appIdentityResponse . sessionToken ,
497444 sessionTokenExpires : new Date ( state . appIdentityResponse . sessionTokenExpires ) ,
498445 } ,
0 commit comments