thirdweb 5.29.3-nightly-ffaff744f72d2cb22896e7501677b48f76ea857a-20240614184424 → 5.29.3-nightly-f8e0c5f84bb3a07a2911b5fce51da3983bb2e9e9-20240614190203
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/exports/{react-native.js → react.native.js} +1 -1
- package/dist/cjs/exports/{react-native.js.map → react.native.js.map} +1 -1
- package/dist/cjs/exports/wallets/embedded.js +4 -4
- package/dist/cjs/exports/wallets/embedded.js.map +1 -1
- package/dist/cjs/exports/wallets/in-app.js +4 -3
- package/dist/cjs/exports/wallets/in-app.js.map +1 -1
- package/dist/cjs/exports/wallets/in-app.native.js +17 -0
- package/dist/cjs/exports/wallets/in-app.native.js.map +1 -0
- package/dist/cjs/exports/wallets.js +10 -7
- package/dist/cjs/exports/wallets.js.map +1 -1
- package/dist/cjs/exports/{react-native/wallets.js → wallets.native.js} +13 -11
- package/dist/cjs/exports/wallets.native.js.map +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/cjs/react/web/wallets/in-app/InAppWalletOTPLoginUI.js +1 -1
- package/dist/cjs/react/web/wallets/in-app/InAppWalletOTPLoginUI.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/create-wallet.js +3 -128
- package/dist/cjs/wallets/create-wallet.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/type.js +6 -1
- package/dist/cjs/wallets/in-app/core/authentication/type.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js +100 -0
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js.map +1 -0
- package/dist/cjs/wallets/in-app/core/wallet/index.js +14 -6
- package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/cjs/wallets/in-app/{core/authentication → native/auth}/index.js +15 -42
- package/dist/cjs/wallets/in-app/native/auth/index.js.map +1 -0
- package/dist/cjs/wallets/in-app/native/{auth.js → auth/native-auth.js} +9 -9
- package/dist/cjs/wallets/in-app/native/auth/native-auth.js.map +1 -0
- package/dist/cjs/wallets/in-app/native/in-app.js +69 -0
- package/dist/cjs/wallets/in-app/native/in-app.js.map +1 -0
- package/dist/cjs/wallets/in-app/native/native-connector.js +9 -10
- package/dist/cjs/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/in-app.js +69 -0
- package/dist/cjs/wallets/in-app/web/in-app.js.map +1 -0
- package/dist/cjs/wallets/in-app/web/lib/auth/iframe-auth.js +219 -0
- package/dist/cjs/wallets/in-app/web/lib/auth/iframe-auth.js.map +1 -0
- package/dist/cjs/wallets/in-app/web/lib/auth/index.js +121 -208
- package/dist/cjs/wallets/in-app/web/lib/auth/index.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js +3 -4
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/esm/exports/{react-native.js → react.native.js} +1 -1
- package/dist/esm/exports/{react-native.js.map → react.native.js.map} +1 -1
- package/dist/esm/exports/wallets/embedded.js +3 -2
- package/dist/esm/exports/wallets/embedded.js.map +1 -1
- package/dist/esm/exports/wallets/in-app.js +4 -2
- package/dist/esm/exports/wallets/in-app.js.map +1 -1
- package/dist/esm/exports/wallets/in-app.native.js +9 -0
- package/dist/esm/exports/wallets/in-app.native.js.map +1 -0
- package/dist/esm/exports/wallets.js +7 -4
- package/dist/esm/exports/wallets.js.map +1 -1
- package/dist/esm/exports/wallets.native.js +23 -0
- package/dist/esm/exports/wallets.native.js.map +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/Details.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/esm/react/web/wallets/in-app/InAppWalletOTPLoginUI.js +1 -1
- package/dist/esm/react/web/wallets/in-app/InAppWalletOTPLoginUI.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/create-wallet.js +1 -125
- package/dist/esm/wallets/create-wallet.js.map +1 -1
- package/dist/esm/wallets/in-app/core/authentication/type.js +5 -0
- package/dist/esm/wallets/in-app/core/authentication/type.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js +95 -0
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js.map +1 -0
- package/dist/esm/wallets/in-app/core/wallet/index.js +14 -6
- package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/esm/wallets/in-app/{core/authentication → native/auth}/index.js +14 -40
- package/dist/esm/wallets/in-app/native/auth/index.js.map +1 -0
- package/dist/esm/wallets/in-app/native/{auth.js → auth/native-auth.js} +9 -9
- package/dist/esm/wallets/in-app/native/auth/native-auth.js.map +1 -0
- package/dist/esm/wallets/in-app/native/in-app.js +65 -0
- package/dist/esm/wallets/in-app/native/in-app.js.map +1 -0
- package/dist/esm/wallets/in-app/native/native-connector.js +2 -3
- package/dist/esm/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/esm/wallets/in-app/web/in-app.js +65 -0
- package/dist/esm/wallets/in-app/web/in-app.js.map +1 -0
- package/dist/esm/wallets/in-app/web/lib/auth/iframe-auth.js +215 -0
- package/dist/esm/wallets/in-app/web/lib/auth/iframe-auth.js.map +1 -0
- package/dist/esm/wallets/in-app/web/lib/auth/index.js +115 -206
- package/dist/esm/wallets/in-app/web/lib/auth/index.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/web-connector.js +2 -3
- package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/types/exports/{react-native.d.ts → react.native.d.ts} +1 -1
- package/dist/types/exports/{react-native.d.ts.map → react.native.d.ts.map} +1 -1
- package/dist/types/exports/wallets/embedded.d.ts +3 -2
- package/dist/types/exports/wallets/embedded.d.ts.map +1 -1
- package/dist/types/exports/wallets/in-app.d.ts +3 -2
- package/dist/types/exports/wallets/in-app.d.ts.map +1 -1
- package/dist/types/exports/wallets/in-app.native.d.ts +5 -0
- package/dist/types/exports/wallets/in-app.native.d.ts.map +1 -0
- package/dist/types/exports/wallets.d.ts +4 -3
- package/dist/types/exports/wallets.d.ts.map +1 -1
- package/dist/types/exports/{react-native/wallets.d.ts → wallets.native.d.ts} +20 -19
- package/dist/types/exports/wallets.native.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/create-wallet.d.ts +0 -53
- package/dist/types/wallets/create-wallet.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/authentication/type.d.ts +4 -0
- package/dist/types/wallets/in-app/core/authentication/type.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/in-app-core.d.ts +16 -0
- package/dist/types/wallets/in-app/core/wallet/in-app-core.d.ts.map +1 -0
- package/dist/types/wallets/in-app/core/wallet/index.d.ts +3 -2
- package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
- package/dist/types/wallets/in-app/{core/authentication → native/auth}/index.d.ts +3 -12
- package/dist/types/wallets/in-app/native/auth/index.d.ts.map +1 -0
- package/dist/types/wallets/in-app/native/{auth.d.ts → auth/native-auth.d.ts} +3 -3
- package/dist/types/wallets/in-app/native/auth/native-auth.d.ts.map +1 -0
- package/dist/types/wallets/in-app/native/in-app.d.ts +56 -0
- package/dist/types/wallets/in-app/native/in-app.d.ts.map +1 -0
- package/dist/types/wallets/in-app/native/native-connector.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/in-app.d.ts +56 -0
- package/dist/types/wallets/in-app/web/in-app.d.ts.map +1 -0
- package/dist/types/wallets/in-app/web/lib/auth/iframe-auth.d.ts +141 -0
- package/dist/types/wallets/in-app/web/lib/auth/iframe-auth.d.ts.map +1 -0
- package/dist/types/wallets/in-app/web/lib/auth/index.d.ts +78 -137
- package/dist/types/wallets/in-app/web/lib/auth/index.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/lib/web-connector.d.ts +1 -1
- package/dist/types/wallets/in-app/web/lib/web-connector.d.ts.map +1 -1
- package/package.json +9 -3
- package/src/exports/wallets/embedded.ts +4 -3
- package/src/exports/wallets/in-app.native.ts +18 -0
- package/src/exports/wallets/in-app.ts +6 -3
- package/src/exports/{react-native/wallets.ts → wallets.native.ts} +21 -19
- package/src/exports/wallets.ts +11 -5
- package/src/react/web/ui/ConnectWallet/Details.tsx +1 -1
- package/src/react/web/wallets/in-app/InAppWalletOTPLoginUI.tsx +1 -1
- package/src/version.ts +1 -1
- package/src/wallets/create-wallet.ts +1 -146
- package/src/wallets/in-app/core/authentication/type.ts +13 -0
- package/src/wallets/in-app/core/wallet/in-app-core.ts +134 -0
- package/src/wallets/in-app/core/wallet/index.ts +16 -5
- package/src/wallets/in-app/{core/authentication → native/auth}/index.ts +15 -57
- package/src/wallets/in-app/native/{auth.ts → auth/native-auth.ts} +10 -10
- package/src/wallets/in-app/native/in-app.ts +70 -0
- package/src/wallets/in-app/native/native-connector.ts +2 -2
- package/src/wallets/in-app/web/in-app.ts +70 -0
- package/src/wallets/in-app/web/lib/auth/iframe-auth.ts +266 -0
- package/src/wallets/in-app/web/lib/auth/index.ts +124 -249
- package/src/wallets/in-app/web/lib/web-connector.ts +2 -2
- package/dist/cjs/exports/react-native/wallets.js.map +0 -1
- package/dist/cjs/wallets/in-app/core/authentication/index.js.map +0 -1
- package/dist/cjs/wallets/in-app/native/auth.js.map +0 -1
- package/dist/esm/exports/react-native/wallets.js +0 -23
- package/dist/esm/exports/react-native/wallets.js.map +0 -1
- package/dist/esm/wallets/in-app/core/authentication/index.js.map +0 -1
- package/dist/esm/wallets/in-app/native/auth.js.map +0 -1
- package/dist/types/exports/react-native/wallets.d.ts.map +0 -1
- package/dist/types/wallets/in-app/core/authentication/index.d.ts.map +0 -1
- package/dist/types/wallets/in-app/native/auth.d.ts.map +0 -1
- /package/src/exports/{react-native.ts → react.native.ts} +0 -0
@@ -1,59 +1,26 @@
|
|
1
1
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
2
|
-
import { isBrowser, isReactNative } from "../../../../utils/platform.js";
|
3
|
-
import type { InAppConnector } from "../interfaces/connector.js";
|
4
2
|
import {
|
5
3
|
type AuthArgsType,
|
6
4
|
type AuthLoginReturnType,
|
7
|
-
|
5
|
+
type GetAuthenticatedUserParams,
|
8
6
|
type PreAuthArgsType,
|
9
7
|
UserWalletStatus,
|
10
|
-
} from "
|
8
|
+
} from "../../core/authentication/type.js";
|
9
|
+
import { getOrCreateInAppWalletConnector } from "../../core/wallet/in-app-core.js";
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
};
|
15
|
-
|
16
|
-
const ewsSDKCache = new WeakMap<ThirdwebClient, InAppConnector>();
|
11
|
+
// ---- KEEP IN SYNC WITH /wallets/in-app/web/lib/auth/index.ts ---- //
|
12
|
+
// duplication needed for separate exports between web and native
|
17
13
|
|
18
14
|
/**
|
19
15
|
* @internal
|
20
16
|
*/
|
21
17
|
async function getInAppWalletConnector(client: ThirdwebClient) {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
let ewSDK: InAppConnector;
|
27
|
-
if (isBrowser()) {
|
28
|
-
const { InAppWebConnector } = await import(
|
29
|
-
"../../web/lib/web-connector.js"
|
30
|
-
);
|
31
|
-
ewSDK = new InAppWebConnector({
|
18
|
+
return getOrCreateInAppWalletConnector(client, async (client) => {
|
19
|
+
const { InAppNativeConnector } = await import("../native-connector.js");
|
20
|
+
return new InAppNativeConnector({
|
32
21
|
client: client,
|
33
22
|
});
|
34
|
-
}
|
35
|
-
const {
|
36
|
-
InAppNativeConnector,
|
37
|
-
} = require("../../native/native-connector.js");
|
38
|
-
ewSDK = new InAppNativeConnector({
|
39
|
-
client,
|
40
|
-
});
|
41
|
-
} else {
|
42
|
-
throw new Error("Unsupported platform");
|
43
|
-
}
|
44
|
-
|
45
|
-
ewsSDKCache.set(client, ewSDK);
|
46
|
-
return ewSDK;
|
47
|
-
}
|
48
|
-
|
49
|
-
/**
|
50
|
-
* @internal
|
51
|
-
*/
|
52
|
-
export async function logoutAuthenticatedUser(
|
53
|
-
options: GetAuthenticatedUserParams,
|
54
|
-
) {
|
55
|
-
const ewSDK = await getInAppWalletConnector(options.client);
|
56
|
-
return ewSDK.logout();
|
23
|
+
});
|
57
24
|
}
|
58
25
|
|
59
26
|
/**
|
@@ -75,8 +42,8 @@ export async function getAuthenticatedUser(
|
|
75
42
|
options: GetAuthenticatedUserParams,
|
76
43
|
) {
|
77
44
|
const { client } = options;
|
78
|
-
const
|
79
|
-
const user = await
|
45
|
+
const connector = await getInAppWalletConnector(client);
|
46
|
+
const user = await connector.getUser();
|
80
47
|
switch (user.status) {
|
81
48
|
case UserWalletStatus.LOGGED_IN_WALLET_INITIALIZED: {
|
82
49
|
return user;
|
@@ -145,8 +112,8 @@ export async function getUserPhoneNumber(options: GetAuthenticatedUserParams) {
|
|
145
112
|
* @wallet
|
146
113
|
*/
|
147
114
|
export async function preAuthenticate(args: PreAuthArgsType) {
|
148
|
-
const
|
149
|
-
return
|
115
|
+
const connector = await getInAppWalletConnector(args.client);
|
116
|
+
return connector.preAuthenticate(args);
|
150
117
|
}
|
151
118
|
|
152
119
|
/**
|
@@ -169,15 +136,6 @@ export async function preAuthenticate(args: PreAuthArgsType) {
|
|
169
136
|
export async function authenticate(
|
170
137
|
args: AuthArgsType,
|
171
138
|
): Promise<AuthLoginReturnType> {
|
172
|
-
const
|
173
|
-
return
|
139
|
+
const connector = await getInAppWalletConnector(args.client);
|
140
|
+
return connector.authenticate(args);
|
174
141
|
}
|
175
|
-
|
176
|
-
export const oauthStrategyToAuthProvider: Record<
|
177
|
-
"google" | "facebook" | "apple",
|
178
|
-
AuthProvider
|
179
|
-
> = {
|
180
|
-
google: AuthProvider.GOOGLE,
|
181
|
-
facebook: AuthProvider.FACEBOOK,
|
182
|
-
apple: AuthProvider.APPLE,
|
183
|
-
};
|
@@ -2,42 +2,42 @@ import type { CognitoUser } from "amazon-cognito-identity-js";
|
|
2
2
|
|
3
3
|
import { Auth } from "aws-amplify";
|
4
4
|
import * as WebBrowser from "expo-web-browser";
|
5
|
-
import type { ThirdwebClient } from "
|
5
|
+
import type { ThirdwebClient } from "../../../../client/client.js";
|
6
6
|
import {
|
7
7
|
AuthProvider,
|
8
8
|
type AuthStoredTokenWithCookieReturnType,
|
9
9
|
type OauthOption,
|
10
10
|
RecoveryShareManagement,
|
11
11
|
type SendEmailOtpReturnType,
|
12
|
-
} from "
|
12
|
+
} from "../../core/authentication/type.js";
|
13
13
|
import {
|
14
14
|
deleteAccount,
|
15
15
|
fetchUserDetails,
|
16
16
|
generateAuthTokenFromCognitoEmailOtp,
|
17
17
|
getSessionHeaders,
|
18
18
|
verifyClientId,
|
19
|
-
} from "
|
19
|
+
} from "../helpers/api/fetchers.js";
|
20
20
|
import {
|
21
21
|
cognitoEmailSignIn,
|
22
22
|
cognitoEmailSignUp,
|
23
23
|
cognitoPhoneSignIn,
|
24
24
|
cognitoPhoneSignUp,
|
25
|
-
} from "
|
25
|
+
} from "../helpers/auth/cognitoAuth.js";
|
26
26
|
import {
|
27
27
|
postAuth,
|
28
28
|
postAuthUserManaged,
|
29
29
|
preAuth,
|
30
|
-
} from "
|
30
|
+
} from "../helpers/auth/middleware.js";
|
31
31
|
import {
|
32
32
|
DOMAIN_URL_2023,
|
33
33
|
ROUTE_AUTH_ENDPOINT_CALLBACK,
|
34
34
|
ROUTE_AUTH_JWT_CALLBACK,
|
35
35
|
ROUTE_HEADLESS_OAUTH_LOGIN,
|
36
|
-
} from "
|
37
|
-
import { createErrorMessage } from "
|
38
|
-
import { isDeviceSharePresentForUser } from "
|
39
|
-
import { getCognitoUser, setCognitoUser } from "
|
40
|
-
import type { VerifiedTokenResponse } from "
|
36
|
+
} from "../helpers/constants.js";
|
37
|
+
import { createErrorMessage } from "../helpers/errors.js";
|
38
|
+
import { isDeviceSharePresentForUser } from "../helpers/storage/local.js";
|
39
|
+
import { getCognitoUser, setCognitoUser } from "../helpers/storage/state.js";
|
40
|
+
import type { VerifiedTokenResponse } from "../helpers/types.js";
|
41
41
|
|
42
42
|
export async function sendVerificationEmail(options: {
|
43
43
|
email: string;
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import type { ThirdwebClient } from "../../../client/client.js";
|
2
|
+
import type { Wallet } from "../../interfaces/wallet.js";
|
3
|
+
import type { CreateWalletArgs } from "../../wallet-types.js";
|
4
|
+
import { createInAppWallet } from "../core/wallet/in-app-core.js";
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Creates an in-app wallet.
|
8
|
+
* @param createOptions - configuration options
|
9
|
+
* @returns The created in-app wallet.
|
10
|
+
* @example
|
11
|
+
* ```ts
|
12
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
13
|
+
*
|
14
|
+
* const wallet = inAppWallet();
|
15
|
+
*
|
16
|
+
* const account = await wallet.connect({
|
17
|
+
* client,
|
18
|
+
* chain,
|
19
|
+
* strategy: "google",
|
20
|
+
* });
|
21
|
+
* ```
|
22
|
+
*
|
23
|
+
* Enable smart accounts and sponsor gas for your users:
|
24
|
+
* ```ts
|
25
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
26
|
+
* const wallet = inAppWallet({
|
27
|
+
* smartAccount: {
|
28
|
+
* chain: sepolia,
|
29
|
+
* sponsorGas: true,
|
30
|
+
* },
|
31
|
+
* });
|
32
|
+
* ```
|
33
|
+
*
|
34
|
+
* Specify a logo for your login page
|
35
|
+
* ```ts
|
36
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
37
|
+
* const wallet = inAppWallet({
|
38
|
+
* metadata: {
|
39
|
+
* image: {
|
40
|
+
* src: "https://example.com/logo.png",
|
41
|
+
* alt: "My logo",
|
42
|
+
* width: 100,
|
43
|
+
* height: 100,
|
44
|
+
* },
|
45
|
+
* },
|
46
|
+
* });
|
47
|
+
* ```
|
48
|
+
*
|
49
|
+
* Hide the ability to export the private key within the Connect Modal
|
50
|
+
* ```ts
|
51
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
52
|
+
* const wallet = inAppWallet({
|
53
|
+
* hidePrivateKeyExport: true
|
54
|
+
* });
|
55
|
+
* ```
|
56
|
+
* @wallet
|
57
|
+
*/
|
58
|
+
export function inAppWallet(
|
59
|
+
createOptions?: CreateWalletArgs<"inApp">[1],
|
60
|
+
): Wallet<"inApp"> {
|
61
|
+
return createInAppWallet({
|
62
|
+
createOptions,
|
63
|
+
connectorFactory: async (client: ThirdwebClient) => {
|
64
|
+
const { InAppNativeConnector } = await import("./native-connector.js");
|
65
|
+
return new InAppNativeConnector({
|
66
|
+
client,
|
67
|
+
});
|
68
|
+
},
|
69
|
+
});
|
70
|
+
}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { ThirdwebClient } from "../../../client/client.js";
|
2
2
|
import type { Account } from "../../interfaces/wallet.js";
|
3
|
-
import { oauthStrategyToAuthProvider } from "../core/authentication/index.js";
|
4
3
|
import {
|
5
4
|
type AuthArgsType,
|
6
5
|
type AuthLoginReturnType,
|
@@ -10,6 +9,7 @@ import {
|
|
10
9
|
type PreAuthArgsType,
|
11
10
|
type SendEmailOtpReturnType,
|
12
11
|
UserWalletStatus,
|
12
|
+
oauthStrategyToAuthProvider,
|
13
13
|
} from "../core/authentication/type.js";
|
14
14
|
import type { InAppConnector } from "../core/interfaces/connector.js";
|
15
15
|
import {
|
@@ -20,7 +20,7 @@ import {
|
|
20
20
|
sendVerificationSms,
|
21
21
|
socialLogin,
|
22
22
|
validateEmailOTP,
|
23
|
-
} from "./auth.js";
|
23
|
+
} from "./auth/native-auth.js";
|
24
24
|
import { fetchUserDetails } from "./helpers/api/fetchers.js";
|
25
25
|
import { logoutUser } from "./helpers/auth/logout.js";
|
26
26
|
import { getWalletUserDetails } from "./helpers/storage/local.js";
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import type { ThirdwebClient } from "../../../client/client.js";
|
2
|
+
import type { Wallet } from "../../interfaces/wallet.js";
|
3
|
+
import type { CreateWalletArgs } from "../../wallet-types.js";
|
4
|
+
import { createInAppWallet } from "../core/wallet/in-app-core.js";
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Creates an in-app wallet.
|
8
|
+
* @param createOptions - configuration options
|
9
|
+
* @returns The created in-app wallet.
|
10
|
+
* @example
|
11
|
+
* ```ts
|
12
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
13
|
+
*
|
14
|
+
* const wallet = inAppWallet();
|
15
|
+
*
|
16
|
+
* const account = await wallet.connect({
|
17
|
+
* client,
|
18
|
+
* chain,
|
19
|
+
* strategy: "google",
|
20
|
+
* });
|
21
|
+
* ```
|
22
|
+
*
|
23
|
+
* Enable smart accounts and sponsor gas for your users:
|
24
|
+
* ```ts
|
25
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
26
|
+
* const wallet = inAppWallet({
|
27
|
+
* smartAccount: {
|
28
|
+
* chain: sepolia,
|
29
|
+
* sponsorGas: true,
|
30
|
+
* },
|
31
|
+
* });
|
32
|
+
* ```
|
33
|
+
*
|
34
|
+
* Specify a logo for your login page
|
35
|
+
* ```ts
|
36
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
37
|
+
* const wallet = inAppWallet({
|
38
|
+
* metadata: {
|
39
|
+
* image: {
|
40
|
+
* src: "https://example.com/logo.png",
|
41
|
+
* alt: "My logo",
|
42
|
+
* width: 100,
|
43
|
+
* height: 100,
|
44
|
+
* },
|
45
|
+
* },
|
46
|
+
* });
|
47
|
+
* ```
|
48
|
+
*
|
49
|
+
* Hide the ability to export the private key within the Connect Modal
|
50
|
+
* ```ts
|
51
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
52
|
+
* const wallet = inAppWallet({
|
53
|
+
* hidePrivateKeyExport: true
|
54
|
+
* });
|
55
|
+
* ```
|
56
|
+
* @wallet
|
57
|
+
*/
|
58
|
+
export function inAppWallet(
|
59
|
+
createOptions?: CreateWalletArgs<"inApp">[1],
|
60
|
+
): Wallet<"inApp"> {
|
61
|
+
return createInAppWallet({
|
62
|
+
createOptions,
|
63
|
+
connectorFactory: async (client: ThirdwebClient) => {
|
64
|
+
const { InAppWebConnector } = await import("./lib/web-connector.js");
|
65
|
+
return new InAppWebConnector({
|
66
|
+
client,
|
67
|
+
});
|
68
|
+
},
|
69
|
+
});
|
70
|
+
}
|
@@ -0,0 +1,266 @@
|
|
1
|
+
import type { ThirdwebClient } from "../../../../../client/client.js";
|
2
|
+
import type {
|
3
|
+
AuthAndWalletRpcReturnType,
|
4
|
+
AuthLoginReturnType,
|
5
|
+
AuthStoredTokenWithCookieReturnType,
|
6
|
+
LogoutReturnType,
|
7
|
+
SendEmailOtpReturnType,
|
8
|
+
} from "../../../core/authentication/type.js";
|
9
|
+
import type { ClientIdWithQuerierType } from "../../types.js";
|
10
|
+
import { LocalStorage } from "../../utils/Storage/LocalStorage.js";
|
11
|
+
import type { InAppWalletIframeCommunicator } from "../../utils/iFrameCommunication/InAppWalletIframeCommunicator.js";
|
12
|
+
import { BaseLogin } from "./base-login.js";
|
13
|
+
|
14
|
+
export type AuthQuerierTypes = {
|
15
|
+
logout: undefined;
|
16
|
+
initIframe: {
|
17
|
+
clientId: string;
|
18
|
+
authCookie: string;
|
19
|
+
walletUserId: string;
|
20
|
+
deviceShareStored: string;
|
21
|
+
};
|
22
|
+
loginWithStoredTokenDetails: {
|
23
|
+
storedToken: AuthStoredTokenWithCookieReturnType["storedToken"];
|
24
|
+
recoveryCode?: string;
|
25
|
+
};
|
26
|
+
};
|
27
|
+
|
28
|
+
/**
|
29
|
+
*
|
30
|
+
*/
|
31
|
+
export class Auth {
|
32
|
+
protected client: ThirdwebClient;
|
33
|
+
protected AuthQuerier: InAppWalletIframeCommunicator<AuthQuerierTypes>;
|
34
|
+
protected localStorage: LocalStorage;
|
35
|
+
protected onAuthSuccess: (
|
36
|
+
authResults: AuthAndWalletRpcReturnType,
|
37
|
+
) => Promise<AuthLoginReturnType>;
|
38
|
+
private BaseLogin: BaseLogin;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Used to manage the user's auth states. This should not be instantiated directly.
|
42
|
+
* Call {@link InAppWalletSdk.auth} instead.
|
43
|
+
* @internal
|
44
|
+
*/
|
45
|
+
constructor({
|
46
|
+
client,
|
47
|
+
querier,
|
48
|
+
onAuthSuccess,
|
49
|
+
baseUrl,
|
50
|
+
}: ClientIdWithQuerierType & {
|
51
|
+
baseUrl: string;
|
52
|
+
onAuthSuccess: (
|
53
|
+
authDetails: AuthAndWalletRpcReturnType,
|
54
|
+
) => Promise<AuthLoginReturnType>;
|
55
|
+
}) {
|
56
|
+
this.client = client;
|
57
|
+
|
58
|
+
this.AuthQuerier = querier;
|
59
|
+
this.localStorage = new LocalStorage({ clientId: client.clientId });
|
60
|
+
this.onAuthSuccess = onAuthSuccess;
|
61
|
+
this.BaseLogin = new BaseLogin({
|
62
|
+
postLogin: async (result) => {
|
63
|
+
return this.postLogin(result);
|
64
|
+
},
|
65
|
+
preLogin: async () => {
|
66
|
+
await this.preLogin();
|
67
|
+
},
|
68
|
+
querier: querier,
|
69
|
+
client,
|
70
|
+
baseUrl,
|
71
|
+
});
|
72
|
+
}
|
73
|
+
|
74
|
+
private async preLogin() {
|
75
|
+
await this.logout();
|
76
|
+
}
|
77
|
+
|
78
|
+
private async postLogin({
|
79
|
+
storedToken,
|
80
|
+
walletDetails,
|
81
|
+
}: AuthAndWalletRpcReturnType): Promise<AuthLoginReturnType> {
|
82
|
+
if (storedToken.shouldStoreCookieString) {
|
83
|
+
await this.localStorage.saveAuthCookie(storedToken.cookieString);
|
84
|
+
}
|
85
|
+
const initializedUser = await this.onAuthSuccess({
|
86
|
+
storedToken,
|
87
|
+
walletDetails,
|
88
|
+
});
|
89
|
+
return initializedUser;
|
90
|
+
}
|
91
|
+
|
92
|
+
async loginWithAuthToken(
|
93
|
+
authToken: AuthStoredTokenWithCookieReturnType,
|
94
|
+
recoveryCode?: string,
|
95
|
+
): Promise<AuthLoginReturnType> {
|
96
|
+
await this.preLogin();
|
97
|
+
const result = await this.AuthQuerier.call<AuthAndWalletRpcReturnType>({
|
98
|
+
procedureName: "loginWithStoredTokenDetails",
|
99
|
+
params: {
|
100
|
+
storedToken: authToken.storedToken,
|
101
|
+
recoveryCode,
|
102
|
+
},
|
103
|
+
});
|
104
|
+
return this.postLogin(result);
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Used to log the user into their thirdweb wallet on your platform via a myriad of auth providers
|
109
|
+
* @example
|
110
|
+
* ```typescript
|
111
|
+
* const thirdwebInAppWallet = new InAppWalletSdk({clientId: "YOUR_CLIENT_ID", chain: "Polygon"})
|
112
|
+
* try {
|
113
|
+
* const user = await thirdwebInAppWallet.auth.loginWithModal();
|
114
|
+
* // user is now logged in
|
115
|
+
* } catch (e) {
|
116
|
+
* // User closed modal or something else went wrong during the authentication process
|
117
|
+
* console.error(e)
|
118
|
+
* }
|
119
|
+
* ```
|
120
|
+
* @returns `{{user: InitializedUser}}` An InitializedUser object.
|
121
|
+
*/
|
122
|
+
async loginWithModal(): Promise<AuthLoginReturnType> {
|
123
|
+
return this.BaseLogin.loginWithModal();
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Used to log the user into their thirdweb wallet using email OTP
|
128
|
+
* @example
|
129
|
+
* ```typescript
|
130
|
+
* // Basic Flow
|
131
|
+
* const thirdwebInAppWallet = new InAppWalletSdk({clientId: "", chain: "Polygon"});
|
132
|
+
* try {
|
133
|
+
* // prompts user to enter the code they received
|
134
|
+
* const user = await thirdwebInAppWallet.auth.loginWithThirdwebEmailOtp({ email : "you@example.com" });
|
135
|
+
* // user is now logged in
|
136
|
+
* } catch (e) {
|
137
|
+
* // User closed the OTP modal or something else went wrong during the authentication process
|
138
|
+
* console.error(e)
|
139
|
+
* }
|
140
|
+
* ```
|
141
|
+
* @param args - args.email: We will send the email an OTP that needs to be entered in order for them to be logged in.
|
142
|
+
* @returns `{{user: InitializedUser}}` An InitializedUser object. See {@link InAppWalletSdk.getUser} for more
|
143
|
+
*/
|
144
|
+
async loginWithEmailOtp(
|
145
|
+
args: Parameters<BaseLogin["loginWithEmailOtp"]>[0],
|
146
|
+
): Promise<AuthLoginReturnType> {
|
147
|
+
return this.BaseLogin.loginWithEmailOtp(args);
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* @internal
|
152
|
+
*/
|
153
|
+
async loginWithCustomJwt(
|
154
|
+
args: Parameters<BaseLogin["loginWithCustomJwt"]>[0],
|
155
|
+
): Promise<AuthLoginReturnType> {
|
156
|
+
return this.BaseLogin.loginWithCustomJwt(args);
|
157
|
+
}
|
158
|
+
|
159
|
+
/**
|
160
|
+
* @internal
|
161
|
+
*/
|
162
|
+
async loginWithCustomAuthEndpoint(
|
163
|
+
args: Parameters<BaseLogin["loginWithCustomAuthEndpoint"]>[0],
|
164
|
+
): Promise<AuthLoginReturnType> {
|
165
|
+
return this.BaseLogin.loginWithCustomAuthEndpoint(args);
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* @internal
|
170
|
+
*/
|
171
|
+
async loginWithOauth(
|
172
|
+
args: Parameters<BaseLogin["loginWithOauth"]>[0],
|
173
|
+
): Promise<AuthLoginReturnType> {
|
174
|
+
return this.BaseLogin.loginWithOauth(args);
|
175
|
+
}
|
176
|
+
|
177
|
+
/**
|
178
|
+
* A headless way to send the users at the passed email an OTP code.
|
179
|
+
* You need to then call {@link Auth.verifyEmailLoginOtp} in order to complete the login process
|
180
|
+
* @example
|
181
|
+
* @param param0.email
|
182
|
+
* ```typescript
|
183
|
+
* const thirdwebInAppWallet = new InAppWalletSdk({clientId: "", chain: "Polygon"});
|
184
|
+
* // sends user an OTP code
|
185
|
+
* try {
|
186
|
+
* await thirdwebInAppWallet.auth.sendEmailLoginOtp({ email : "you@example.com" });
|
187
|
+
* } catch(e) {
|
188
|
+
* // Error Sending user's email an OTP code
|
189
|
+
* console.error(e);
|
190
|
+
* }
|
191
|
+
*
|
192
|
+
* // Then when your user is ready to verify their OTP
|
193
|
+
* try {
|
194
|
+
* const user = await thirdwebInAppWallet.auth.verifyEmailLoginOtp({ email: "you@example.com", otp: "6-DIGIT_CODE_HERE" });
|
195
|
+
* } catch(e) {
|
196
|
+
* // Error verifying the OTP code
|
197
|
+
* console.error(e)
|
198
|
+
* }
|
199
|
+
* ```
|
200
|
+
* @param param0 - param0.email We will send the email an OTP that needs to be entered in order for them to be logged in.
|
201
|
+
* @returns `{{ isNewUser: boolean }}` IsNewUser indicates if the user is a new user to your platform
|
202
|
+
* @internal
|
203
|
+
*/
|
204
|
+
async sendEmailLoginOtp({
|
205
|
+
email,
|
206
|
+
}: Parameters<
|
207
|
+
BaseLogin["sendEmailLoginOtp"]
|
208
|
+
>[0]): Promise<SendEmailOtpReturnType> {
|
209
|
+
return this.BaseLogin.sendEmailLoginOtp({
|
210
|
+
email,
|
211
|
+
});
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
* @internal
|
216
|
+
*/
|
217
|
+
async sendSmsLoginOtp({
|
218
|
+
phoneNumber,
|
219
|
+
}: Parameters<
|
220
|
+
BaseLogin["sendSmsLoginOtp"]
|
221
|
+
>[0]): Promise<SendEmailOtpReturnType> {
|
222
|
+
return this.BaseLogin.sendSmsLoginOtp({
|
223
|
+
phoneNumber,
|
224
|
+
});
|
225
|
+
}
|
226
|
+
|
227
|
+
/**
|
228
|
+
* Used to verify the otp that the user receives from thirdweb
|
229
|
+
*
|
230
|
+
* See {@link Auth.sendEmailLoginOtp} for how the headless call flow looks like. Simply swap out the calls to `loginWithThirdwebEmailOtp` with `verifyThirdwebEmailLoginOtp`
|
231
|
+
* @param args - props.email We will send the email an OTP that needs to be entered in order for them to be logged in.
|
232
|
+
* props.otp The code that the user received in their email
|
233
|
+
* @returns `{{user: InitializedUser}}` An InitializedUser object containing the user's status, wallet, authDetails, and more
|
234
|
+
* @internal
|
235
|
+
*/
|
236
|
+
async verifyEmailLoginOtp(
|
237
|
+
args: Parameters<BaseLogin["verifyEmailLoginOtp"]>[0],
|
238
|
+
) {
|
239
|
+
return this.BaseLogin.verifyEmailLoginOtp(args);
|
240
|
+
}
|
241
|
+
|
242
|
+
/**
|
243
|
+
* @internal
|
244
|
+
*/
|
245
|
+
async verifySmsLoginOtp(args: Parameters<BaseLogin["verifySmsLoginOtp"]>[0]) {
|
246
|
+
return this.BaseLogin.verifySmsLoginOtp(args);
|
247
|
+
}
|
248
|
+
|
249
|
+
/**
|
250
|
+
* Logs any existing user out of their wallet.
|
251
|
+
* @returns `{{success: boolean}}` true if a user is successfully logged out. false if there's no user currently logged in.
|
252
|
+
* @internal
|
253
|
+
*/
|
254
|
+
async logout(): Promise<LogoutReturnType> {
|
255
|
+
const { success } = await this.AuthQuerier.call<LogoutReturnType>({
|
256
|
+
procedureName: "logout",
|
257
|
+
params: undefined,
|
258
|
+
});
|
259
|
+
const isRemoveAuthCookie = await this.localStorage.removeAuthCookie();
|
260
|
+
const isRemoveUserId = await this.localStorage.removeWalletUserId();
|
261
|
+
|
262
|
+
return {
|
263
|
+
success: success || isRemoveAuthCookie || isRemoveUserId,
|
264
|
+
};
|
265
|
+
}
|
266
|
+
}
|