-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ecosystem refactor part 4: react native edition (#4783)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing wallet functionalities and authentication processes in the `thirdweb` library, particularly for ecosystem wallets in React Native. It introduces new wallet interfaces, updates existing methods, and improves error handling for user authentication. ### Detailed summary - Removed obsolete `web-wallet.ts.changeset/chilled-dancers-cheer.md` file. - Added support for ecosystem wallets in `useAutoConnect` hook. - Updated `createInAppWallet` to include new `createOptions` structure. - Defined `IWebWallet` interface with methods for wallet setup and user status. - Expanded `EcosystemWalletCreationOptions` to include authentication options. - Modified `getUserStatus` to handle user status retrieval with better error logging. - Updated `InAppWebConnector` to utilize the new wallet interfaces and methods. - Implemented `ShardedWallet` class with user wallet status and account retrieval. - Enhanced error handling in the authentication processes across various modules. - Removed deprecated methods from `native-auth.ts`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information
1 parent
1f1f99d
commit 944d56f
Showing
21 changed files
with
364 additions
and
716 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"thirdweb": minor | ||
--- | ||
|
||
Enable ecosystem wallets in React Native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/thirdweb/src/wallets/in-app/core/authentication/authEndpoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { ThirdwebClient } from "../../../../client/client.js"; | ||
import { getSessionHeaders } from "../../native/helpers/api/fetchers.js"; | ||
import { ROUTE_AUTH_ENDPOINT_CALLBACK } from "../../native/helpers/constants.js"; | ||
import { createErrorMessage } from "../../native/helpers/errors.js"; | ||
import type { ClientScopedStorage } from "./client-scoped-storage.js"; | ||
import type { AuthStoredTokenWithCookieReturnType } from "./types.js"; | ||
|
||
export async function authEndpoint(args: { | ||
payload: string; | ||
client: ThirdwebClient; | ||
storage: ClientScopedStorage; | ||
}): Promise<AuthStoredTokenWithCookieReturnType> { | ||
const resp = await fetch(ROUTE_AUTH_ENDPOINT_CALLBACK, { | ||
method: "POST", | ||
headers: { | ||
...getSessionHeaders(), | ||
}, | ||
body: JSON.stringify({ | ||
payload: args.payload, | ||
developerClientId: args.client.clientId, | ||
}), | ||
}); | ||
if (!resp.ok) { | ||
const error = await resp.json(); | ||
throw new Error( | ||
`Custom auth endpoint authentication error: ${error.message}`, | ||
); | ||
} | ||
|
||
try { | ||
const { verifiedToken } = await resp.json(); | ||
|
||
return { storedToken: verifiedToken }; | ||
} catch (e) { | ||
throw new Error( | ||
createErrorMessage( | ||
"Malformed response from post auth_endpoint authentication", | ||
e, | ||
), | ||
); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/thirdweb/src/wallets/in-app/core/authentication/jwt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { ThirdwebClient } from "../../../../client/client.js"; | ||
import { getSessionHeaders } from "../../native/helpers/api/fetchers.js"; | ||
import { ROUTE_AUTH_JWT_CALLBACK } from "../../native/helpers/constants.js"; | ||
import { createErrorMessage } from "../../native/helpers/errors.js"; | ||
import type { ClientScopedStorage } from "./client-scoped-storage.js"; | ||
import type { AuthStoredTokenWithCookieReturnType } from "./types.js"; | ||
|
||
export async function customJwt(args: { | ||
jwt: string; | ||
client: ThirdwebClient; | ||
storage: ClientScopedStorage; | ||
}): Promise<AuthStoredTokenWithCookieReturnType> { | ||
const resp = await fetch(ROUTE_AUTH_JWT_CALLBACK, { | ||
method: "POST", | ||
headers: { | ||
...getSessionHeaders(), | ||
}, | ||
body: JSON.stringify({ | ||
jwt: args.jwt, | ||
developerClientId: args.client.clientId, | ||
}), | ||
}); | ||
|
||
if (!resp.ok) { | ||
const error = await resp.json(); | ||
throw new Error(`JWT authentication error: ${error.message}`); | ||
} | ||
|
||
try { | ||
const { verifiedToken } = await resp.json(); | ||
return { storedToken: verifiedToken }; | ||
} catch (e) { | ||
throw new Error( | ||
createErrorMessage("Malformed response from post jwt authentication", e), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/thirdweb/src/wallets/in-app/core/wallet/web-wallet.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { Account } from "../../../interfaces/wallet.js"; | ||
import type { | ||
AuthResultAndRecoveryCode, | ||
GetUser, | ||
} from "../authentication/types.js"; | ||
|
||
/** | ||
* | ||
*/ | ||
export interface IWebWallet { | ||
postWalletSetUp(authResult: AuthResultAndRecoveryCode): Promise<void>; | ||
getUserWalletStatus(): Promise<GetUser>; | ||
getAccount(): Promise<Account>; | ||
} |
Oops, something went wrong.