Skip to content

Commit 085380a

Browse files
authored
Merge branch 'main' into jd/sync-chains-10-24
Signed-off-by: Jonas Daniels <jonas.daniels@outlook.com>
2 parents 91efe54 + 80def43 commit 085380a

File tree

76 files changed

+423
-478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+423
-478
lines changed

.changeset/forty-beers-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/sdk": patch
3+
---
4+
5+
Remove barrel files

.changeset/friendly-toys-agree.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/react-native": patch
3+
---
4+
5+
Migrate embedded wallet to new API in React Native

.changeset/metal-moles-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/sdk": patch
3+
---
4+
5+
Fix double trailing slash when downloading merkle data

packages/react-native/src/evm/wallets/connectors/embedded-wallet/embedded/auth.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export async function validateEmailOTP({
111111

112112
try {
113113
const storedToken: AuthStoredTokenWithCookieReturnType["storedToken"] = {
114-
jwtToken: verifiedToken.rawToken,
114+
jwtToken: verifiedToken.jwtToken,
115115
authDetails: verifiedToken.authDetails,
116116
authProvider: verifiedToken.authProvider,
117117
developerClientId: verifiedToken.developerClientId,
@@ -135,15 +135,16 @@ export async function validateEmailOTP({
135135

136136
export async function socialLogin(oauthOptions: OauthOption, clientId: string) {
137137
const headlessLoginLinkWithParams = `${ROUTE_HEADLESS_GOOGLE_LOGIN}?authProvider=${encodeURIComponent(
138-
"google",
138+
oauthOptions.provider,
139139
)}&baseUrl=${encodeURIComponent(
140-
"https://ews.thirdweb.com",
140+
"https://embedded-wallet.thirdweb.com",
141141
)}&platform=${encodeURIComponent("mobile")}`;
142142

143143
const resp = await fetch(headlessLoginLinkWithParams);
144144

145145
if (!resp.ok) {
146-
throw new Error("Error getting headless login link");
146+
const error = await resp.json();
147+
throw new Error(`Error getting headless login link: ${error.message}`);
147148
}
148149

149150
const json = await resp.json();
@@ -211,29 +212,28 @@ export async function customJwt(authOptions: AuthOptions, clientId: string) {
211212
method: "POST",
212213
headers: { "Content-Type": "application/json" },
213214
body: JSON.stringify({
214-
jwtToken: jwt,
215-
authProvider: AuthProvider.CUSTOM_JWT,
215+
jwt: jwt,
216216
developerClientId: clientId,
217217
}),
218218
});
219219
if (!resp.ok) {
220-
const { error } = await resp.json();
221-
throw new Error(`JWT authentication error: ${error} `);
220+
const error = await resp.json();
221+
throw new Error(`JWT authentication error: ${error.message} `);
222222
}
223223

224224
try {
225225
const { verifiedToken, verifiedTokenJwtString } = await resp.json();
226226

227227
const toStoreToken: AuthStoredTokenWithCookieReturnType["storedToken"] = {
228-
jwtToken: verifiedToken.rawToken,
228+
jwtToken: verifiedToken.jwtToken,
229229
authProvider: verifiedToken.authProvider,
230230
authDetails: {
231231
...verifiedToken.authDetails,
232232
email: verifiedToken.authDetails.email,
233233
},
234234
developerClientId: verifiedToken.developerClientId,
235235
cookieString: verifiedTokenJwtString,
236-
shouldStoreCookieString: false,
236+
shouldStoreCookieString: true,
237237
isNewUser: verifiedToken.isNewUser,
238238
};
239239

packages/react-native/src/evm/wallets/connectors/embedded-wallet/embedded/helpers/api/fetchers.ts

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
import { CognitoUserSession } from "amazon-cognito-identity-js";
66
import {
77
ROUTE_GET_EMBEDDED_WALLET_DETAILS,
8-
ROUTE_INIT_RECOVERY_CODE_FREE_WALLET,
98
ROUTE_STORE_USER_SHARES,
109
ROUTE_VERIFY_THIRDWEB_CLIENT_ID,
1110
ROUTE_VERIFY_COGNITO_OTP,
@@ -14,7 +13,7 @@ import { getAuthTokenClient } from "../storage/local";
1413
import * as Application from "expo-application";
1514

1615
const EMBEDDED_WALLET_TOKEN_HEADER = "embedded-wallet-token";
17-
const PAPER_CLIENT_ID_HEADER = "x-paper-client-id";
16+
const PAPER_CLIENT_ID_HEADER = "x-thirdweb-client-id";
1817
const BUNDLE_ID_HEADER = "x-bundle-id";
1918
const APP_BUNDLE_ID = Application.applicationId || "";
2019

@@ -28,9 +27,9 @@ export const verifyClientId = async (clientId: string) => {
2827
body: JSON.stringify({ clientId, parentDomain: "" }),
2928
});
3029
if (!resp.ok) {
31-
const { error } = await resp.json();
30+
const error = await resp.json();
3231
throw new Error(
33-
`Something went wrong generating auth token from user cognito email otp. ${error}`,
32+
`Something went wrong generating auth token from user cognito email otp. ${error.message}`,
3433
);
3534
}
3635
return {
@@ -66,17 +65,13 @@ export const authFetchEmbeddedWalletUser = async (
6665

6766
export async function getEmbeddedWalletUserDetail(args: {
6867
email?: string;
69-
userWalletId?: string;
7068
clientId: string;
7169
}) {
7270
const url = new URL(ROUTE_GET_EMBEDDED_WALLET_DETAILS);
7371
if (args) {
7472
if (args.email) {
7573
url.searchParams.append("email", args.email);
7674
}
77-
if (args.userWalletId) {
78-
url.searchParams.append("userWalletId", args.userWalletId);
79-
}
8075
url.searchParams.append("clientId", args.clientId);
8176
}
8277
const resp = await authFetchEmbeddedWalletUser(
@@ -87,12 +82,15 @@ export async function getEmbeddedWalletUserDetail(args: {
8782
},
8883
);
8984
if (!resp.ok) {
90-
const { error } = await resp.json();
91-
throw new Error(`Something went wrong determining wallet type. ${error}`);
85+
const error = await resp.json();
86+
throw new Error(
87+
`Something went wrong determining wallet type. ${error.message}`,
88+
);
9289
}
9390
const result = (await resp.json()) as
9491
| {
9592
isNewUser: true;
93+
recoveryShareManagement: RecoveryShareManagement;
9694
}
9795
| {
9896
isNewUser: false;
@@ -118,59 +116,33 @@ export async function generateAuthTokenFromCognitoEmailOtp(
118116
id_token: session.getIdToken().getJwtToken(),
119117
developerClientId: clientId,
120118
otpMethod: "email",
121-
recoveryShareManagement: RecoveryShareManagement.AWS_MANAGED,
122119
}),
123120
});
124121
if (!resp.ok) {
125-
const { error } = await resp.json();
122+
const error = await resp.json();
126123
throw new Error(
127-
`Something went wrong generating auth token from user cognito email otp. ${error}`,
124+
`Something went wrong generating auth token from user cognito email otp. ${error.message}`,
128125
);
129126
}
130127
const respJ = await resp.json();
131128
return respJ as {
132129
verifiedToken: {
133-
rawToken: string;
130+
jwtToken: string;
131+
authProvider: AuthProvider;
132+
developerClientId: string;
134133
authDetails: {
135134
email?: string;
136135
userWalletId: string;
137136
recoveryCode?: string;
137+
cookieString?: string;
138138
recoveryShareManagement: RecoveryShareManagement;
139139
};
140-
authProvider: AuthProvider;
141-
userId: string;
142-
developerClientId: string;
143140
isNewUser: boolean;
144141
};
145142
verifiedTokenJwtString: string;
146143
};
147144
}
148145

149-
export async function initWalletWithoutRecoveryCode({
150-
clientId,
151-
}: {
152-
clientId: string;
153-
}) {
154-
const resp = await authFetchEmbeddedWalletUser(
155-
{ clientId },
156-
ROUTE_INIT_RECOVERY_CODE_FREE_WALLET,
157-
{
158-
method: "POST",
159-
headers: { "Content-Type": "application/json" },
160-
body: JSON.stringify({
161-
clientId,
162-
}),
163-
},
164-
);
165-
if (!resp.ok) {
166-
const { error } = await resp.json();
167-
console.error(`Error initializing wallet: ${error} `);
168-
return { success: false };
169-
}
170-
171-
return { success: true };
172-
}
173-
174146
export async function storeUserShares({
175147
clientId,
176148
walletAddress,
@@ -198,11 +170,13 @@ export async function storeUserShares({
198170
}),
199171
},
200172
);
173+
201174
if (!resp.ok) {
202-
const { error } = await resp.json();
175+
const error = await resp.json();
176+
203177
throw new Error(
204178
`Something went wrong storing user wallet shares: ${JSON.stringify(
205-
error,
179+
error.message,
206180
null,
207181
2,
208182
)}`,
@@ -219,10 +193,10 @@ export async function getUserShares(clientId: string, getShareUrl: URL) {
219193
},
220194
);
221195
if (!resp.ok) {
222-
const { error } = await resp.json();
196+
const error = await resp.json();
223197
throw new Error(
224198
`Something went wrong getting user's wallet: ${JSON.stringify(
225-
error,
199+
error.message,
226200
null,
227201
2,
228202
)} `,

packages/react-native/src/evm/wallets/connectors/embedded-wallet/embedded/helpers/constants.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@ export const COGNITO_IDENTITY_POOL_ID =
1919
export const GENERATE_RECOVERY_PASSWORD_LAMBDA_FUNCTION =
2020
"arn:aws:lambda:us-west-2:324457261097:function:recovery-share-password-GenerateRecoverySharePassw-bbE5ZbVAToil";
2121

22-
const BASE_URL = "https://ews.thirdweb.com";
23-
const ROUTE_2022_08_12_API_BASE_PATH = `${BASE_URL}/api/2022-08-12`;
22+
const BASE_URL_2023 = "https://embedded-wallet.thirdweb.com/";
23+
const ROUTE_2023_10_20_API_BASE_PATH = `${BASE_URL_2023}api/2023-10-20`;
2424

25-
export const ROUTE_GET_EMBEDDED_WALLET_DETAILS = `${ROUTE_2022_08_12_API_BASE_PATH}/embedded-wallet/user-wallet-details`;
26-
export const ROUTE_VERIFY_COGNITO_OTP = `${ROUTE_2022_08_12_API_BASE_PATH}/embedded-wallet/verify-cognito-otp`;
25+
export const ROUTE_GET_EMBEDDED_WALLET_DETAILS = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/embedded-wallet-user-details`;
26+
export const ROUTE_VERIFY_COGNITO_OTP = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/validate-cognito-email-otp`;
2727
export const ROUTE_COGNITO_IDENTITY_POOL_URL = `cognito-idp.${AWS_REGION}.amazonaws.com/${COGNITO_USER_POOL_ID}`;
28-
export const ROUTE_INIT_RECOVERY_CODE_FREE_WALLET = `${ROUTE_2022_08_12_API_BASE_PATH}/embedded-wallet/init-recovery-code-free-wallet`;
29-
export const ROUTE_STORE_USER_SHARES = `${ROUTE_2022_08_12_API_BASE_PATH}/embedded-wallet/store-shares`;
30-
export const ROUTE_GET_USER_SHARES = `${ROUTE_2022_08_12_API_BASE_PATH}/embedded-wallet/get-shares`;
31-
export const ROUTE_VERIFY_THIRDWEB_CLIENT_ID = `${ROUTE_2022_08_12_API_BASE_PATH}/embedded-wallet/verify-thirdweb-client-id`;
32-
export const ROUTE_AUTH_JWT_CALLBACK = `${ROUTE_2022_08_12_API_BASE_PATH}/embedded-wallet/jwt-callback`;
28+
export const ROUTE_STORE_USER_SHARES = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/embedded-wallet-shares`;
29+
export const ROUTE_GET_USER_SHARES = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/embedded-wallet-shares`;
30+
export const ROUTE_VERIFY_THIRDWEB_CLIENT_ID = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/verify-thirdweb-client-id`;
31+
export const ROUTE_AUTH_JWT_CALLBACK = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/validate-custom-jwt`;
3332

34-
export const ROUTE_HEADLESS_GOOGLE_LOGIN = `${BASE_URL}/api/2022-08-12/embedded-wallet/headless-login-link`;
33+
export const ROUTE_HEADLESS_GOOGLE_LOGIN = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/headless-oauth-login-link`;
3534

36-
export const ROUTE_AUTH_COGNITO_ID_TOKEN = `${ROUTE_2022_08_12_API_BASE_PATH}/embedded-wallet/cognito-id-token`;
35+
export const ROUTE_AUTH_COGNITO_ID_TOKEN = `${ROUTE_2023_10_20_API_BASE_PATH}/embedded-wallet/cognito-id-token`;

packages/react-native/src/evm/wallets/connectors/embedded-wallet/embedded/helpers/wallet/creation.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { SetUpWalletRpcReturnType } from "@paperxyz/embedded-wallet-service-sdk";
22
import { Wallet, utils } from "ethers";
33
import * as secrets from "secrets.js-34r7h";
4-
import {
5-
initWalletWithoutRecoveryCode,
6-
storeUserShares,
7-
} from "../api/fetchers";
4+
import { storeUserShares } from "../api/fetchers";
85

96
import { logoutUser } from "../auth/logout";
107
import {
@@ -21,11 +18,6 @@ export async function setUpNewUserWallet(
2118
clientId: string,
2219
) {
2320
try {
24-
// We are using a recovery code override, we mark the wallet as initialized so we don't generate another one the next time
25-
const { success } = await initWalletWithoutRecoveryCode({ clientId });
26-
if (!success) {
27-
throw new Error("Error initializing wallet without recovery code");
28-
}
2921
return await createEmbeddedWallet({
3022
clientId,
3123
recoveryCode: recoveryCode,
@@ -52,6 +44,7 @@ async function createEmbeddedWallet({
5244
} & SetUpWalletRpcReturnType
5345
> {
5446
const walletDetails = createWalletShares();
47+
5548
const maybeDeviceShare = await storeShares({
5649
clientId,
5750
walletAddress: walletDetails.publicAddress,

packages/react-native/src/evm/wallets/connectors/embedded-wallet/embedded/helpers/wallet/recoveryCode.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import {InvokeCommand, LambdaClient} from '@aws-sdk/client-lambda';
2-
import {fromCognitoIdentityPool} from '@aws-sdk/credential-providers';
1+
import { InvokeCommand, LambdaClient } from "@aws-sdk/client-lambda";
2+
import { fromCognitoIdentityPool } from "@aws-sdk/credential-providers";
33

4-
import {authFetchEmbeddedWalletUser} from '../api/fetchers';
4+
import { authFetchEmbeddedWalletUser } from "../api/fetchers";
55
import {
66
AWS_REGION,
77
COGNITO_IDENTITY_POOL_ID,
88
GENERATE_RECOVERY_PASSWORD_LAMBDA_FUNCTION,
99
ROUTE_AUTH_COGNITO_ID_TOKEN,
1010
ROUTE_COGNITO_IDENTITY_POOL_URL,
11-
} from '../constants';
11+
} from "../constants";
1212

1313
export async function getCognitoRecoveryPassword(clientId: string) {
1414
const idTokenResponse = await authFetchEmbeddedWalletUser(
15-
{clientId},
15+
{ clientId },
1616
ROUTE_AUTH_COGNITO_ID_TOKEN,
1717
{
18-
method: 'GET',
18+
method: "GET",
1919
},
2020
);
2121
if (!idTokenResponse.ok) {
@@ -28,9 +28,7 @@ export async function getCognitoRecoveryPassword(clientId: string) {
2828
);
2929
}
3030
const idTokenResult = await idTokenResponse.json();
31-
const {
32-
data: {id_token: idToken, access_token: accessToken},
33-
} = idTokenResult;
31+
const { idToken, accessToken } = idTokenResult;
3432

3533
const cognitoIdentity = fromCognitoIdentityPool({
3634
clientConfig: {
@@ -62,9 +60,9 @@ export async function getCognitoRecoveryPassword(clientId: string) {
6260
};
6361
const data = await lambdaClient.send(new InvokeCommand(params));
6462
if (!data.Payload) {
65-
throw new Error('No payload');
63+
throw new Error("No payload");
6664
}
67-
const encKeyResult = JSON.parse(Buffer.from(data.Payload).toString('utf-8'));
65+
const encKeyResult = JSON.parse(Buffer.from(data.Payload).toString("utf-8"));
6866

6967
const result = JSON.parse(encKeyResult.body).recoveryShareEncKey as string;
7068

packages/react-native/src/evm/wallets/connectors/embedded-wallet/embedded/helpers/wallet/retrieval.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,21 @@ export async function getShares<
7979
const queryParams: Record<string, boolean> = {};
8080
if (authShare.toRetrieve) {
8181
queryParams.getEncryptedAuthShare = true;
82+
} else {
83+
queryParams.getEncryptedAuthShare = false;
8284
}
8385
if (recoveryShare.toRetrieve) {
8486
queryParams.getEncryptedRecoveryShare = true;
8587
if (!recoveryShare.recoveryCode) {
8688
// purposely using a vague name to prevent people from inspecting url from figuring out what it does
8789
// so as to not cause huge debates on the technicality of the custodial // non-custodial
8890
queryParams.useSealedSecret = true;
91+
} else {
92+
queryParams.useSealedSecret = false;
8993
}
94+
} else {
95+
queryParams.getEncryptedRecoveryShare = false;
96+
queryParams.useSealedSecret = false;
9097
}
9198

9299
const getShareUrl = new URL(ROUTE_GET_USER_SHARES);

packages/react-native/src/evm/wallets/wallets/embedded/BackupAccount.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export const AccountRecovery = ({ close, goBack }: EnterPasswordProps) => {
3434
const onNextPress = async () => {};
3535

3636
const onCodeCopyPress = async (code: string) => {
37-
console.log("code", code);
38-
3937
await Clipboard.setStringAsync(code);
4038
setCodeCopied(true);
4139
};

0 commit comments

Comments
 (0)