Skip to content

Commit 3cca8b3

Browse files
committed
allow to list public spaces
1 parent 2403b28 commit 3cca8b3

File tree

10 files changed

+21
-3
lines changed

10 files changed

+21
-3
lines changed

apps/connect/src/routes/authenticate.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,11 @@ function AuthenticateComponent() {
282282
nonce: appInfo.appNonce,
283283
ephemeralPublicKey: appInfo.ephemeralEncryptionPublicKey,
284284
appIdentityAddress: appIdentity.address,
285+
appIdentityAddressPrivateKey: appIdentity.addressPrivateKey,
286+
accountAddress: accountAddress,
285287
encryptionPrivateKey: appIdentity.encryptionPrivateKey,
286288
signaturePrivateKey: appIdentity.signaturePrivateKey,
287289
signaturePublicKey: appIdentity.signaturePublicKey,
288-
appIdentityAddressPrivateKey: appIdentity.addressPrivateKey,
289290
encryptionPublicKey: appIdentity.encryptionPublicKey,
290291
spaces: spacesData?.map((space) => ({ id: space.id })) ?? [],
291292
expiry: appInfo.expiry,
@@ -364,6 +365,7 @@ function AuthenticateComponent() {
364365
appIdentity: {
365366
address: newAppIdentity.address,
366367
addressPrivateKey: newAppIdentity.addressPrivateKey,
368+
accountAddress,
367369
encryptionPrivateKey: keys.encryptionPrivateKey,
368370
signaturePrivateKey: keys.signaturePrivateKey,
369371
encryptionPublicKey: newAppIdentity.encryptionPublicKey,
@@ -420,6 +422,7 @@ function AuthenticateComponent() {
420422
appIdentity: {
421423
address: decryptedIdentity.address,
422424
addressPrivateKey: decryptedIdentity.addressPrivateKey,
425+
accountAddress: decryptedIdentity.accountAddress,
423426
encryptionPrivateKey: decryptedIdentity.encryptionPrivateKey,
424427
signaturePrivateKey: decryptedIdentity.signaturePrivateKey,
425428
encryptionPublicKey: decryptedIdentity.encryptionPublicKey,

apps/events/src/routes/authenticate-success.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function RouteComponent() {
4444
setIdentity({
4545
address: parsedAuthParams.appIdentityAddress,
4646
addressPrivateKey: parsedAuthParams.appIdentityAddressPrivateKey,
47+
accountAddress: parsedAuthParams.accountAddress,
4748
signaturePublicKey: parsedAuthParams.signaturePublicKey,
4849
signaturePrivateKey: parsedAuthParams.signaturePrivateKey,
4950
encryptionPublicKey: parsedAuthParams.encryptionPublicKey,

packages/hypergraph-react/src/hooks/use-spaces.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { store } from '@graphprotocol/hypergraph/store';
12
import { useQuery } from '@tanstack/react-query';
3+
import { useSelector } from '@xstate/store/react';
24
import { gql, request } from 'graphql-request';
35
import { GEO_API_TESTNET_ENDPOINT } from '../internal/constants.js';
46

@@ -27,11 +29,12 @@ type PublicSpacesQueryResult = {
2729
};
2830

2931
export const useSpaces = (params: { mode: 'public' }) => {
32+
const accountAddress = useSelector(store, (state) => state.context.identity?.accountAddress);
3033
return useQuery({
3134
queryKey: ['hypergraph-spaces', params.mode],
3235
queryFn: async () => {
3336
const result = await request<PublicSpacesQueryResult>(GEO_API_TESTNET_ENDPOINT, publicSpacesQueryDocument, {
34-
accountAddress: '0xBE0298aF8D440bEFA78E7e8A538D8ecBFF06bfC7',
37+
accountAddress,
3538
});
3639
return result?.spaces
3740
? result.spaces.map((space) => ({

packages/hypergraph/src/connect/create-callback-params.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type CreateAuthUrlParams = {
88
appId: string;
99
appIdentityAddress: string;
1010
appIdentityAddressPrivateKey: string;
11+
accountAddress: string;
1112
signaturePublicKey: string;
1213
signaturePrivateKey: string;
1314
encryptionPublicKey: string;

packages/hypergraph/src/connect/identity-encryption.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,6 @@ export const decryptAppIdentity = async (
228228
signaturePrivateKey,
229229
address: appIdentityAddress,
230230
addressPrivateKey: appIdentityAddressPrivateKey,
231+
accountAddress,
231232
};
232233
};

packages/hypergraph/src/connect/parse-callback-params.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const parseCallbackParams = ({
5252
return Effect.succeed({
5353
appIdentityAddress: data.appIdentityAddress,
5454
appIdentityAddressPrivateKey: data.appIdentityAddressPrivateKey,
55+
accountAddress: data.accountAddress,
5556
signaturePublicKey: data.signaturePublicKey,
5657
signaturePrivateKey: data.signaturePrivateKey,
5758
encryptionPublicKey: data.encryptionPublicKey,

packages/hypergraph/src/connect/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export type PrivateAppIdentity = IdentityKeys & {
6060
addressPrivateKey: string;
6161
sessionToken: string;
6262
sessionTokenExpires: Date;
63+
accountAddress: string;
6364
};
6465

6566
export class InvalidIdentityError {

packages/hypergraph/src/identity/auth-storage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Storage } from './types.js';
44
export const storeIdentity = (storage: Storage, identity: PrivateAppIdentity) => {
55
storage.setItem('hypergraph:app-identity-address', identity.address);
66
storage.setItem('hypergraph:app-identity-address-private-key', identity.addressPrivateKey);
7+
storage.setItem('hypergraph:app-identity-account-address', identity.accountAddress);
78
storage.setItem('hypergraph:signature-public-key', identity.signaturePublicKey);
89
storage.setItem('hypergraph:signature-private-key', identity.signaturePrivateKey);
910
storage.setItem('hypergraph:encryption-public-key', identity.encryptionPublicKey);
@@ -15,6 +16,7 @@ export const storeIdentity = (storage: Storage, identity: PrivateAppIdentity) =>
1516
export const loadIdentity = (storage: Storage): PrivateAppIdentity | null => {
1617
const address = storage.getItem('hypergraph:app-identity-address');
1718
const addressPrivateKey = storage.getItem('hypergraph:app-identity-address-private-key');
19+
const accountAddress = storage.getItem('hypergraph:app-identity-account-address');
1820
const signaturePublicKey = storage.getItem('hypergraph:signature-public-key');
1921
const signaturePrivateKey = storage.getItem('hypergraph:signature-private-key');
2022
const encryptionPublicKey = storage.getItem('hypergraph:encryption-public-key');
@@ -24,6 +26,7 @@ export const loadIdentity = (storage: Storage): PrivateAppIdentity | null => {
2426
if (
2527
!address ||
2628
!addressPrivateKey ||
29+
!accountAddress ||
2730
!signaturePublicKey ||
2831
!signaturePrivateKey ||
2932
!encryptionPublicKey ||
@@ -36,6 +39,7 @@ export const loadIdentity = (storage: Storage): PrivateAppIdentity | null => {
3639
return {
3740
address,
3841
addressPrivateKey,
42+
accountAddress,
3943
signaturePublicKey,
4044
signaturePrivateKey,
4145
encryptionPublicKey,
@@ -48,6 +52,7 @@ export const loadIdentity = (storage: Storage): PrivateAppIdentity | null => {
4852
export const wipeIdentity = (storage: Storage) => {
4953
storage.removeItem('hypergraph:app-identity-address');
5054
storage.removeItem('hypergraph:app-identity-address-private-key');
55+
storage.removeItem('hypergraph:app-identity-account-address');
5156
storage.removeItem('hypergraph:signature-public-key');
5257
storage.removeItem('hypergraph:signature-private-key');
5358
storage.removeItem('hypergraph:encryption-public-key');

packages/hypergraph/src/store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ export const store: Store<StoreContext, StoreEvent, GenericEventObject> = create
489489
return {
490490
...context,
491491
authenticated: true,
492-
identity: event.identity,
492+
// TODO: remove hard-coded account address and use the one from the identity
493+
identity: { ...event.identity, accountAddress: '0xBE0298aF8D440bEFA78E7e8A538D8ecBFF06bfC7' },
493494
};
494495
},
495496
resetAuth: (context) => {

packages/hypergraph/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type ConnectAuthPayload = Schema.Schema.Type<typeof ConnectAuthPayload>;
2020
export const ConnectCallbackResult = Schema.Struct({
2121
appIdentityAddress: Schema.String,
2222
appIdentityAddressPrivateKey: Schema.String,
23+
accountAddress: Schema.String,
2324
signaturePublicKey: Schema.String,
2425
signaturePrivateKey: Schema.String,
2526
encryptionPublicKey: Schema.String,

0 commit comments

Comments
 (0)