Skip to content

Commit 8b2d7b1

Browse files
committed
fix: Disable app check + fix creating convos user
1 parent 84e94fc commit 8b2d7b1

14 files changed

+77
-121
lines changed

App.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useLogoutOnJwtRefreshError } from "@/features/authentication/use-logout
66
import { useInitializeMultiInboxClient } from "@/features/multi-inbox/multi-inbox.client";
77
import { useSetupStreamingSubscriptions } from "@/features/streams/streams";
88
import { $globalStyles } from "@/theme/styles";
9+
import { useThemeProvider } from "@/theme/use-app-theme";
910
import { configure as configureCoinbase } from "@coinbase/wallet-mobile-sdk";
1011
import { BottomSheetModalProvider } from "@design-system/BottomSheet/BottomSheetModalProvider";
1112
import { useReactQueryDevTools } from "@dev-plugins/react-query";
@@ -14,8 +15,6 @@ import { PrivyProvider } from "@privy-io/expo";
1415
import { SmartWalletsProvider } from "@privy-io/expo/smart-wallets";
1516
import { queryClient } from "@queries/queryClient";
1617
import { QueryClientProvider } from "@tanstack/react-query";
17-
import { useThemeProvider } from "@/theme/use-app-theme";
18-
import { setupAppAttest } from "@utils/appCheck";
1918
import { useCoinbaseWalletListener } from "@utils/coinbaseWallet";
2019
import * as Clipboard from "expo-clipboard";
2120
import "expo-dev-client";
@@ -72,7 +71,8 @@ export function App() {
7271
useThemeProvider();
7372

7473
useEffect(() => {
75-
setupAppAttest();
74+
// Disabled for now until we go live and it works with bun
75+
// setupAppAttest();
7676
}, []);
7777

7878
useCoinbaseWalletListener(true, coinbaseUrl);

SlimApp.tsx

-72
This file was deleted.

config/config.types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ export type IConfig = {
5050
universalLinks: string[];
5151
privy: IPrivyConfig;
5252
evm: IEvmConfig;
53-
appCheckDebugToken?: string;
53+
appCheckDebugToken: string | undefined;
5454
reactQueryEncryptionKey: string;
5555
};

config/development.ts

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { IConfig } from "@/config/config.types";
2-
import { Platform } from "react-native";
32
import { shared } from "./shared";
43

54
export const developmentConfig: IConfig = {
@@ -12,10 +11,6 @@ export const developmentConfig: IConfig = {
1211
universalLinks: ["dev.converse.xyz/", "dev.getconverse.app/"].flatMap(
1312
(domain) => [`https://${domain}`, `http://${domain}`, domain]
1413
),
15-
appCheckDebugToken:
16-
Platform.OS === "android"
17-
? process.env.EXPO_PUBLIC_FIREBASE_APP_CHECK_DEBUG_TOKEN_ANDROID
18-
: process.env.EXPO_PUBLIC_FIREBASE_APP_CHECK_DEBUG_TOKEN_IOS,
1914
evm: {
2015
rpcEndpoint: process.env.EXPO_PUBLIC_EVM_RPC_ENDPOINT,
2116
transactionChainId: "0x14a34", // Base Sepolia

config/index.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { isDev, isPreview } from "@/utils/getEnv";
22
import { developmentConfig } from "./development";
3-
import { productionConfig } from "./production";
43
import { previewConfig } from "./preview";
5-
import { z } from "zod";
4+
import { productionConfig } from "./production";
65

76
// todo: use zod for env and stop typing in multiple places
87
// crash on first build step rather than at runtime
@@ -20,6 +19,20 @@ import { z } from "zod";
2019
// // // Validate config at startup
2120
// // configSchema.parse(Config);
2221

22+
/**
23+
* Helpful when debugging locally using other environments
24+
*/
25+
const API_URL = process.env.EXPO_PUBLIC_CONVOS_API_URI;
26+
const EXPO_ENV = process.env.EXPO_ENV;
27+
28+
if (API_URL.includes("localhost")) {
29+
if (EXPO_ENV && EXPO_ENV !== "development") {
30+
throw new Error(
31+
"Using localhost API URL in non-dev environment. Did you forget to pull env vars?"
32+
);
33+
}
34+
}
35+
2336
export const getConfig = () => {
2437
if (isDev) return developmentConfig;
2538
if (isPreview) return previewConfig;

config/shared.ts

+4
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ export const shared = {
5858
thirdwebClientId: process.env.EXPO_PUBLIC_THIRDWEB_CLIENT_ID,
5959
reactQueryEncryptionKey:
6060
process.env.EXPO_PUBLIC_SECURE_REACT_QUERY_ENCRYPTION_KEY,
61+
appCheckDebugToken:
62+
Platform.OS === "android"
63+
? process.env.EXPO_PUBLIC_FIREBASE_APP_CHECK_DEBUG_TOKEN_ANDROID
64+
: process.env.EXPO_PUBLIC_FIREBASE_APP_CHECK_DEBUG_TOKEN_IOS,
6165
} as const satisfies Partial<IConfig>;

design-system/Header/Header.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ITouchableOpacityProps } from "../TouchableOpacity";
1313
import { VStack } from "../VStack";
1414
import { HeaderAction } from "./HeaderAction";
1515
import { useHeaderHeight } from "@/design-system/Header/Header.utils";
16+
import { debugBorder } from "@/utils/debug-style";
1617

1718
export type HeaderProps = {
1819
titleStyle?: StyleProp<TextStyle>;

design-system/Header/HeaderAction.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Icon } from "../Icon/Icon";
77
import { Pressable } from "../Pressable";
88
import { ITextProps, Text } from "../Text";
99
import { ITouchableOpacityProps, TouchableOpacity } from "../TouchableOpacity";
10+
import { debugBorder } from "@/utils/debug-style";
1011

1112
type HeaderActionProps = {
1213
backgroundColor?: string;
@@ -75,7 +76,6 @@ const $actionTextContainer: ThemedStyle<ViewStyle> = ({ spacing }) => ({
7576
flexGrow: 0,
7677
alignItems: "center",
7778
justifyContent: "center",
78-
height: "100%",
7979
paddingHorizontal: spacing.md,
8080
zIndex: 2,
8181
});

utils/appCheck.ts features/authentication/app-check.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { config } from "@/config";
55
import { captureError } from "@/utils/capture-error";
66
import { GenericError } from "@/utils/error";
77
import { firebase } from "@react-native-firebase/app-check";
8-
import { logger } from "./logger";
8+
import { logger } from "../../utils/logger";
99

1010
const appCheck = firebase.appCheck();
1111

@@ -35,6 +35,7 @@ export const tryGetAppCheckToken = async ({
3535
return undefined;
3636
}
3737
};
38+
3839
export async function setupAppAttest() {
3940
logger.debug("[setupAppAttest] Starting app attestation setup");
4041

@@ -43,15 +44,17 @@ export async function setupAppAttest() {
4344
"[setupAppAttest] Created new React Native Firebase App Check provider"
4445
);
4546

47+
// Configure provider based on environment and platform
4648
rnfbProvider.configure({
4749
android: {
48-
provider: __DEV__ ? "debug" : "playIntegrity",
50+
provider: __DEV__ ? ("debug" as const) : ("playIntegrity" as const),
4951
debugToken: config.appCheckDebugToken,
5052
},
5153
apple: {
52-
provider: __DEV__ ? "debug" : "appAttestWithDeviceCheckFallback",
53-
// Will be intentionally undefined in non-dev environments
54-
debugToken: config.appCheckDebugToken,
54+
provider: __DEV__
55+
? ("debug" as const)
56+
: ("appAttestWithDeviceCheckFallback" as const),
57+
debugToken: config.appCheckDebugToken, // Undefined in non-dev environments
5558
},
5659
});
5760
logger.debug(

features/authentication/authentication.headers.ts

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { tryGetAppCheckToken } from "../../utils/appCheck";
1+
import { tryGetAppCheckToken } from "./app-check";
22
import { MultiInboxClient } from "@/features/multi-inbox/multi-inbox.client";
33
import {
44
getSafeCurrentSender,
@@ -20,11 +20,8 @@ export const CONVOS_AUTH_TOKEN_HEADER_KEY = "X-Convos-AuthToken";
2020

2121
export type XmtpApiHeaders = {
2222
[XMTP_INSTALLATION_ID_HEADER_KEY]: string;
23-
2423
[XMTP_INBOX_ID_HEADER_KEY]: string;
25-
2624
[FIREBASE_APP_CHECK_HEADER_KEY]: string;
27-
2825
[XMTP_SIGNATURE_HEADER_KEY]: string;
2926
};
3027

@@ -38,7 +35,6 @@ export type XmtpApiHeaders = {
3835
* Privy passkeys. See authentication.readme.md for more details.
3936
*/
4037
import { logger } from "@/utils/logger";
41-
4238
export async function getConvosAuthenticationHeaders(): Promise<XmtpApiHeaders> {
4339
logger.debug(
4440
"[getConvosAuthenticationHeaders] Starting to get authentication headers"
@@ -49,28 +45,31 @@ export async function getConvosAuthenticationHeaders(): Promise<XmtpApiHeaders>
4945
`[getConvosAuthenticationHeaders] Current ethereum address: ${currentEthereumAddress}`
5046
);
5147

48+
const { multiInboxClientRestorationState } = useMultiInboxStore.getState();
5249
const areInboxesRestored =
53-
useMultiInboxStore.getState().multiInboxClientRestorationState ===
50+
multiInboxClientRestorationState ===
5451
MultiInboxClientRestorationStates.restored;
52+
5553
logger.debug(
56-
`[getConvosAuthenticationHeaders] Are inboxes restored: ${
57-
useMultiInboxStore.getState().multiInboxClientRestorationState
58-
}`
54+
`[getConvosAuthenticationHeaders] Are inboxes restored: ${multiInboxClientRestorationState}`
5955
);
60-
const appCheckToken = await tryGetAppCheckToken();
56+
57+
// Disabled for now until we go live and it works with bun
58+
const appCheckToken = "123";
59+
// const appCheckToken = await tryGetAppCheckToken();
60+
// if (!appCheckToken) {
61+
// logger.error(
62+
// "[getConvosAuthenticationHeaders] No App Check Token Available"
63+
// );
64+
// throw new AuthenticationError(
65+
// "No App Check Token Available. This indicates that we believe the app is not running on an authentic build of our application on a device that has not been tampered with."
66+
// );
67+
// }
68+
6169
const inboxClient = MultiInboxClient.instance.getInboxClientForAddress({
6270
ethereumAddress: currentEthereumAddress,
6371
});
6472

65-
if (!appCheckToken) {
66-
logger.error(
67-
"[getConvosAuthenticationHeaders] No App Check Token Available"
68-
);
69-
throw new AuthenticationError(
70-
"No App Check Token Available. This indicates that we believe the app is not running on an authentic build of our application on a device that has not been tampered with."
71-
);
72-
}
73-
7473
if (!areInboxesRestored) {
7574
logger.error("[getConvosAuthenticationHeaders] Inboxes not restored");
7675
throw new AuthenticationError(
@@ -90,6 +89,7 @@ export async function getConvosAuthenticationHeaders(): Promise<XmtpApiHeaders>
9089
logger.debug(
9190
"[getConvosAuthenticationHeaders] Signing app check token with installation key"
9291
);
92+
9393
const rawAppCheckTokenSignature = await inboxClient.signWithInstallationKey(
9494
appCheckToken
9595
);
@@ -98,11 +98,12 @@ export async function getConvosAuthenticationHeaders(): Promise<XmtpApiHeaders>
9898
logger.debug(
9999
"[getConvosAuthenticationHeaders] Successfully created authentication headers"
100100
);
101+
101102
return {
102103
[XMTP_INSTALLATION_ID_HEADER_KEY]: inboxClient.installationId,
103104
[XMTP_INBOX_ID_HEADER_KEY]: inboxClient.inboxId,
104-
[FIREBASE_APP_CHECK_HEADER_KEY]: appCheckToken,
105105
[XMTP_SIGNATURE_HEADER_KEY]: appCheckTokenSignatureHexString,
106+
[FIREBASE_APP_CHECK_HEADER_KEY]: appCheckToken, // Disabled for now until we go live and it works with bun
106107
};
107108
}
108109

features/onboarding/hooks/use-signup-with-passkey.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
createInboxWithSigner,
44
createSmartWalletSigner,
55
} from "@/features/onboarding/utils/passkey";
6+
import { authLogger } from "@/utils/logger";
67
import { useEmbeddedEthereumWallet } from "@privy-io/expo";
78
import { useSignupWithPasskey as usePrivySignupWithPasskey } from "@privy-io/expo/passkey";
89
import { useSmartWallets } from "@privy-io/expo/smart-wallets";
@@ -14,38 +15,41 @@ export function useSignupWithPasskey() {
1415
const { signupWithPasskey: privySignupWithPasskey } =
1516
usePrivySignupWithPasskey();
1617
const [isSigningUp, setIsSigningUp] = useState(false);
17-
1818
const clientRef = useRef(smartWalletClient);
1919

2020
useEffect(() => {
2121
clientRef.current = smartWalletClient;
2222
}, [smartWalletClient]);
2323

24+
// Helper function to wait for smart wallet client initialization
2425
async function waitForSmartWalletClient(maxAttempts = 10) {
2526
for (let i = 0; i < maxAttempts; i++) {
2627
if (clientRef.current) {
2728
return clientRef.current;
2829
}
2930
await new Promise((resolve) => setTimeout(resolve, 1000));
3031
}
31-
3232
throw new Error("Timeout waiting for smart wallet client");
3333
}
3434

3535
const signup = async () => {
3636
try {
3737
setIsSigningUp(true);
3838

39-
await privySignupWithPasskey({
40-
relyingParty: RELYING_PARTY,
41-
});
39+
// Step 1: Passkey signup
40+
authLogger.debug(`[Passkey Signup] Starting passkey registration`);
41+
await privySignupWithPasskey({ relyingParty: RELYING_PARTY });
4242

43+
// Step 2: Wallet creation
44+
authLogger.debug(`[Wallet Setup] Creating embedded and smart wallets`);
4345
await createEmbeddedWallet();
44-
4546
const smartWalletclient = await waitForSmartWalletClient();
46-
4747
const signer = createSmartWalletSigner(smartWalletclient);
4848

49+
// Step 3: Inbox creation
50+
authLogger.debug(
51+
`[Inbox Setup] Creating inbox for address: ${smartWalletclient.account.address}`
52+
);
4953
const { inboxId } = await createInboxWithSigner(signer);
5054

5155
return {
@@ -59,5 +63,5 @@ export function useSignupWithPasskey() {
5963
}
6064
};
6165

62-
return { signup, isSigningUp: isSigningUp };
66+
return { signup, isSigningUp };
6367
}

0 commit comments

Comments
 (0)