thirdweb 5.64.3-nightly-ddec3dadcc260e0d4d0ed2b43c502e0915a14203-20241029000326 → 5.64.4-nightly-043ee925981bdc39649d30ad65d2fce922515ab0-20241030000335
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/wallets.js.map +1 -1
- package/dist/cjs/react/core/utils/isSmartWallet.js +4 -2
- package/dist/cjs/react/core/utils/isSmartWallet.js.map +1 -1
- package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js +1 -1
- package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/ecosystem/get-ecosystem-wallet-auth-options.js +23 -17
- package/dist/cjs/wallets/ecosystem/get-ecosystem-wallet-auth-options.js.map +1 -1
- package/dist/cjs/wallets/ecosystem/get-ecosystem-wallet-info.js +4 -13
- package/dist/cjs/wallets/ecosystem/get-ecosystem-wallet-info.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/passkeys.js +5 -5
- package/dist/cjs/wallets/in-app/core/authentication/passkeys.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js +56 -4
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/index.js +2 -50
- package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/esm/exports/wallets.js.map +1 -1
- package/dist/esm/react/core/utils/isSmartWallet.js +4 -2
- package/dist/esm/react/core/utils/isSmartWallet.js.map +1 -1
- package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js +2 -2
- package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/ecosystem/get-ecosystem-wallet-auth-options.js +22 -16
- package/dist/esm/wallets/ecosystem/get-ecosystem-wallet-auth-options.js.map +1 -1
- package/dist/esm/wallets/ecosystem/get-ecosystem-wallet-info.js +4 -13
- package/dist/esm/wallets/ecosystem/get-ecosystem-wallet-info.js.map +1 -1
- package/dist/esm/wallets/in-app/core/authentication/passkeys.js +5 -5
- package/dist/esm/wallets/in-app/core/authentication/passkeys.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js +56 -4
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/index.js +2 -50
- package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/types/exports/wallets.d.ts +1 -1
- package/dist/types/exports/wallets.d.ts.map +1 -1
- package/dist/types/react/core/utils/isSmartWallet.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/ecosystem/get-ecosystem-wallet-auth-options.d.ts +5 -1
- package/dist/types/wallets/ecosystem/get-ecosystem-wallet-auth-options.d.ts.map +1 -1
- package/dist/types/wallets/ecosystem/get-ecosystem-wallet-info.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/authentication/passkeys.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/in-app-core.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/index.d.ts +2 -3
- package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/types.d.ts +2 -0
- package/dist/types/wallets/in-app/core/wallet/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/exports/wallets.ts +1 -0
- package/src/react/core/utils/isSmartWallet.ts +4 -2
- package/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx +2 -2
- package/src/version.ts +1 -1
- package/src/wallets/ecosystem/get-ecosystem-wallet-auth-options.ts +36 -23
- package/src/wallets/ecosystem/get-ecosystem-wallet-info.ts +5 -21
- package/src/wallets/in-app/core/authentication/passkeys.ts +5 -7
- package/src/wallets/in-app/core/wallet/in-app-core.ts +62 -4
- package/src/wallets/in-app/core/wallet/index.ts +0 -59
- package/src/wallets/in-app/core/wallet/types.ts +3 -0
@@ -1,8 +1,13 @@
|
|
1
1
|
import { getThirdwebBaseUrl } from "../../utils/domains.js";
|
2
|
+
import { withCache } from "../../utils/promise/withCache.js";
|
2
3
|
import type { AuthOption } from "../types.js";
|
3
4
|
import type { EcosystemWalletId } from "../wallet-types.js";
|
4
5
|
|
5
6
|
export type EcosystemOptions = {
|
7
|
+
name: string;
|
8
|
+
imageUrl?: string;
|
9
|
+
slug: string;
|
10
|
+
homepage?: string;
|
6
11
|
authOptions: AuthOption[];
|
7
12
|
smartAccountOptions: SmartAccountOptions;
|
8
13
|
};
|
@@ -19,32 +24,40 @@ type SmartAccountOptions = {
|
|
19
24
|
* @returns {AuthOption[] | undefined} The auth options for the ecosystem wallet.
|
20
25
|
* @internal
|
21
26
|
*/
|
22
|
-
export async function
|
27
|
+
export async function getEcosystemInfo(
|
23
28
|
walletId: EcosystemWalletId,
|
24
|
-
): Promise<EcosystemOptions
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
): Promise<EcosystemOptions> {
|
30
|
+
return withCache(
|
31
|
+
async () => {
|
32
|
+
const res = await fetch(
|
33
|
+
`${getThirdwebBaseUrl("inAppWallet")}/api/2024-05-05/ecosystem-wallet`,
|
34
|
+
{
|
35
|
+
headers: {
|
36
|
+
"x-ecosystem-id": walletId,
|
37
|
+
},
|
38
|
+
},
|
39
|
+
);
|
33
40
|
|
34
|
-
|
41
|
+
const data = await res.json();
|
35
42
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
if (!data || data.code === "UNAUTHORIZED") {
|
44
|
+
throw new Error(
|
45
|
+
data.message ||
|
46
|
+
`Could not find ecosystem wallet with id ${walletId}, please check your ecosystem wallet configuration.`,
|
47
|
+
);
|
48
|
+
}
|
42
49
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
50
|
+
// siwe is the auth option in the backend, but we want to use wallet as the auth option in the frontend
|
51
|
+
if (data.authOptions?.includes("siwe")) {
|
52
|
+
data.authOptions = data.authOptions.filter((o: string) => o !== "siwe");
|
53
|
+
data.authOptions.push("wallet");
|
54
|
+
}
|
48
55
|
|
49
|
-
|
56
|
+
return data;
|
57
|
+
},
|
58
|
+
{
|
59
|
+
cacheKey: `ecosystem-wallet-options-${walletId}`,
|
60
|
+
cacheTime: 1000 * 60 * 5, // 5 mins
|
61
|
+
},
|
62
|
+
);
|
50
63
|
}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { getThirdwebBaseUrl } from "../../utils/domains.js";
|
2
1
|
import type { Prettify } from "../../utils/type-utils.js";
|
3
2
|
import type { WalletInfo } from "../wallet-info.js";
|
4
3
|
import type { EcosystemWalletId } from "../wallet-types.js";
|
4
|
+
import { getEcosystemInfo } from "./get-ecosystem-wallet-auth-options.js";
|
5
5
|
|
6
6
|
/**
|
7
7
|
* Fetches metadata for a given ecosystem wallet.
|
@@ -14,29 +14,13 @@ import type { EcosystemWalletId } from "../wallet-types.js";
|
|
14
14
|
export async function getEcosystemWalletInfo(
|
15
15
|
walletId: EcosystemWalletId,
|
16
16
|
): Promise<Prettify<WalletInfo>> {
|
17
|
-
const
|
18
|
-
`${getThirdwebBaseUrl("inAppWallet")}/api/2024-05-05/ecosystem-wallet`,
|
19
|
-
{
|
20
|
-
headers: {
|
21
|
-
"x-ecosystem-id": walletId,
|
22
|
-
},
|
23
|
-
},
|
24
|
-
);
|
25
|
-
|
26
|
-
const data = await res.json();
|
27
|
-
|
28
|
-
if (!data || data.code === "UNAUTHORIZED") {
|
29
|
-
throw new Error(
|
30
|
-
data.message ||
|
31
|
-
`Could not find ecosystem wallet with id ${walletId}, please check your ecosystem wallet configuration.`,
|
32
|
-
);
|
33
|
-
}
|
17
|
+
const data = await getEcosystemInfo(walletId);
|
34
18
|
|
35
19
|
return {
|
36
20
|
id: walletId,
|
37
|
-
name: data.name
|
38
|
-
image_id: data.imageUrl
|
39
|
-
homepage: data.homepage
|
21
|
+
name: data.name,
|
22
|
+
image_id: data.imageUrl || "",
|
23
|
+
homepage: data.homepage || "",
|
40
24
|
rdns: null,
|
41
25
|
app: {
|
42
26
|
browser: null,
|
@@ -137,19 +137,17 @@ export async function loginWithPasskey(options: {
|
|
137
137
|
}
|
138
138
|
const fetchWithId = getClientFetch(options.client, options.ecosystem);
|
139
139
|
// 1. request challenge from server/iframe
|
140
|
-
const
|
141
|
-
|
140
|
+
const [challengeData, credentialId] = await Promise.all([
|
141
|
+
fetchWithId(getChallengePath("sign-in")).then((r) => r.json()),
|
142
|
+
options.storage?.getPasskeyCredentialId(),
|
143
|
+
]);
|
142
144
|
if (!challengeData.challenge) {
|
143
145
|
throw new Error("No challenge received");
|
144
146
|
}
|
145
147
|
const challenge = challengeData.challenge;
|
146
|
-
// 1.2. find the user's credentialId in local storage
|
147
|
-
const credentialId =
|
148
|
-
(await options.storage?.getPasskeyCredentialId()) ?? undefined;
|
149
|
-
|
150
148
|
// 2. initiate login
|
151
149
|
const authentication = await options.passkeyClient.authenticate({
|
152
|
-
credentialId,
|
150
|
+
credentialId: credentialId ?? undefined,
|
153
151
|
challenge,
|
154
152
|
rp: options.rp,
|
155
153
|
});
|
@@ -2,6 +2,7 @@ import { trackConnect } from "../../../../analytics/track/connect.js";
|
|
2
2
|
import type { Chain } from "../../../../chains/types.js";
|
3
3
|
import { getCachedChainIfExists } from "../../../../chains/utils.js";
|
4
4
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
5
|
+
import { getEcosystemInfo } from "../../../ecosystem/get-ecosystem-wallet-auth-options.js";
|
5
6
|
import type { Account, Wallet } from "../../../interfaces/wallet.js";
|
6
7
|
import { createWalletEmitter } from "../../../wallet-emitter.js";
|
7
8
|
import type {
|
@@ -38,9 +39,10 @@ export function createInAppWallet(args: {
|
|
38
39
|
connectorFactory: (client: ThirdwebClient) => Promise<InAppConnector>;
|
39
40
|
ecosystem?: Ecosystem;
|
40
41
|
}): Wallet<"inApp" | EcosystemWalletId> {
|
41
|
-
const { createOptions, connectorFactory, ecosystem } = args;
|
42
|
+
const { createOptions: _createOptions, connectorFactory, ecosystem } = args;
|
42
43
|
const walletId = ecosystem ? ecosystem.id : "inApp";
|
43
44
|
const emitter = createWalletEmitter<"inApp">();
|
45
|
+
let createOptions = _createOptions;
|
44
46
|
let account: Account | undefined = undefined;
|
45
47
|
let chain: Chain | undefined = undefined;
|
46
48
|
let client: ThirdwebClient | undefined;
|
@@ -66,11 +68,32 @@ export function createInAppWallet(args: {
|
|
66
68
|
connectorFactory,
|
67
69
|
ecosystem,
|
68
70
|
);
|
71
|
+
|
72
|
+
if (ecosystem) {
|
73
|
+
const ecosystemOptions = await getEcosystemInfo(ecosystem.id);
|
74
|
+
const smartAccountOptions = ecosystemOptions?.smartAccountOptions;
|
75
|
+
if (smartAccountOptions) {
|
76
|
+
const preferredChain = options.chain;
|
77
|
+
if (!preferredChain) {
|
78
|
+
throw new Error(
|
79
|
+
"Chain is required for ecosystem smart accounts, pass it via connect() or via UI components",
|
80
|
+
);
|
81
|
+
}
|
82
|
+
createOptions = {
|
83
|
+
...createOptions,
|
84
|
+
smartAccount: {
|
85
|
+
chain: preferredChain,
|
86
|
+
sponsorGas: smartAccountOptions.sponsorGas,
|
87
|
+
factoryAddress: smartAccountOptions.accountFactoryAddress,
|
88
|
+
},
|
89
|
+
};
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
69
93
|
const [connectedAccount, connectedChain] = await autoConnectInAppWallet(
|
70
94
|
options,
|
71
95
|
createOptions,
|
72
96
|
connector,
|
73
|
-
ecosystem,
|
74
97
|
);
|
75
98
|
|
76
99
|
// set the states
|
@@ -94,11 +117,31 @@ export function createInAppWallet(args: {
|
|
94
117
|
ecosystem,
|
95
118
|
);
|
96
119
|
|
120
|
+
if (ecosystem) {
|
121
|
+
const ecosystemOptions = await getEcosystemInfo(ecosystem.id);
|
122
|
+
const smartAccountOptions = ecosystemOptions?.smartAccountOptions;
|
123
|
+
if (smartAccountOptions) {
|
124
|
+
const preferredChain = options.chain;
|
125
|
+
if (!preferredChain) {
|
126
|
+
throw new Error(
|
127
|
+
"Chain is required for ecosystem smart accounts, pass it via connect() or via UI components",
|
128
|
+
);
|
129
|
+
}
|
130
|
+
createOptions = {
|
131
|
+
...createOptions,
|
132
|
+
smartAccount: {
|
133
|
+
chain: preferredChain,
|
134
|
+
sponsorGas: smartAccountOptions.sponsorGas,
|
135
|
+
factoryAddress: smartAccountOptions.accountFactoryAddress,
|
136
|
+
},
|
137
|
+
};
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
97
141
|
const [connectedAccount, connectedChain] = await connectInAppWallet(
|
98
142
|
options,
|
99
143
|
createOptions,
|
100
144
|
connector,
|
101
|
-
ecosystem,
|
102
145
|
);
|
103
146
|
// set the states
|
104
147
|
client = options.client;
|
@@ -139,6 +182,22 @@ export function createInAppWallet(args: {
|
|
139
182
|
connectorFactory,
|
140
183
|
ecosystem,
|
141
184
|
);
|
185
|
+
|
186
|
+
if (ecosystem) {
|
187
|
+
const ecosystemOptions = await getEcosystemInfo(ecosystem.id);
|
188
|
+
const smartAccountOptions = ecosystemOptions?.smartAccountOptions;
|
189
|
+
if (smartAccountOptions) {
|
190
|
+
createOptions = {
|
191
|
+
...createOptions,
|
192
|
+
smartAccount: {
|
193
|
+
chain: newChain,
|
194
|
+
sponsorGas: smartAccountOptions.sponsorGas,
|
195
|
+
factoryAddress: smartAccountOptions.accountFactoryAddress,
|
196
|
+
},
|
197
|
+
};
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
142
201
|
const [connectedAccount, connectedChain] = await autoConnectInAppWallet(
|
143
202
|
{
|
144
203
|
chain: newChain,
|
@@ -146,7 +205,6 @@ export function createInAppWallet(args: {
|
|
146
205
|
},
|
147
206
|
createOptions,
|
148
207
|
connector,
|
149
|
-
ecosystem,
|
150
208
|
);
|
151
209
|
account = connectedAccount;
|
152
210
|
chain = connectedChain;
|
@@ -1,12 +1,10 @@
|
|
1
1
|
import { ethereum } from "../../../../chains/chain-definitions/ethereum.js";
|
2
2
|
import type { Chain } from "../../../../chains/types.js";
|
3
|
-
import { getCachedChain } from "../../../../chains/utils.js";
|
4
3
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
5
4
|
import {
|
6
5
|
type SocialAuthOption,
|
7
6
|
socialAuthOptions,
|
8
7
|
} from "../../../../wallets/types.js";
|
9
|
-
import { getEcosystemOptions } from "../../../ecosystem/get-ecosystem-wallet-auth-options.js";
|
10
8
|
import type { Account, Wallet } from "../../../interfaces/wallet.js";
|
11
9
|
import type { EcosystemWalletId, WalletId } from "../../../wallet-types.js";
|
12
10
|
import type {
|
@@ -15,7 +13,6 @@ import type {
|
|
15
13
|
WalletConnectionOption,
|
16
14
|
} from "../../../wallet-types.js";
|
17
15
|
import type { InAppConnector } from "../interfaces/connector.js";
|
18
|
-
import type { Ecosystem } from "./types.js";
|
19
16
|
|
20
17
|
/**
|
21
18
|
* Checks if the provided wallet is an in-app wallet.
|
@@ -40,7 +37,6 @@ export async function connectInAppWallet(
|
|
40
37
|
| CreateWalletArgs<"inApp">[1]
|
41
38
|
| CreateWalletArgs<EcosystemWalletId>[1],
|
42
39
|
connector: InAppConnector,
|
43
|
-
ecosystem: Ecosystem | undefined,
|
44
40
|
): Promise<[Account, Chain]> {
|
45
41
|
if (
|
46
42
|
// if auth mode is not specified, the default is popup
|
@@ -77,33 +73,6 @@ export async function connectInAppWallet(
|
|
77
73
|
});
|
78
74
|
}
|
79
75
|
|
80
|
-
if (ecosystem) {
|
81
|
-
const ecosystemOptions = await getEcosystemOptions(ecosystem.id);
|
82
|
-
const smartAccountOptions = ecosystemOptions?.smartAccountOptions;
|
83
|
-
if (smartAccountOptions) {
|
84
|
-
const allowedChains = smartAccountOptions.chainIds;
|
85
|
-
const firstAllowedChain = allowedChains[0];
|
86
|
-
if (!firstAllowedChain) {
|
87
|
-
throw new Error(
|
88
|
-
"At least one chain must be allowed for ecosystem smart account",
|
89
|
-
);
|
90
|
-
}
|
91
|
-
const preferredChain =
|
92
|
-
options.chain && allowedChains.includes(options.chain.id)
|
93
|
-
? options.chain
|
94
|
-
: getCachedChain(firstAllowedChain);
|
95
|
-
return convertToSmartAccount({
|
96
|
-
client: options.client,
|
97
|
-
authAccount,
|
98
|
-
smartAccountOptions: {
|
99
|
-
chain: preferredChain,
|
100
|
-
sponsorGas: smartAccountOptions.sponsorGas,
|
101
|
-
factoryAddress: smartAccountOptions.accountFactoryAddress,
|
102
|
-
},
|
103
|
-
});
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
76
|
return [authAccount, options.chain || ethereum] as const;
|
108
77
|
}
|
109
78
|
|
@@ -118,7 +87,6 @@ export async function autoConnectInAppWallet(
|
|
118
87
|
| CreateWalletArgs<"inApp">[1]
|
119
88
|
| CreateWalletArgs<EcosystemWalletId>[1],
|
120
89
|
connector: InAppConnector,
|
121
|
-
ecosystem: Ecosystem | undefined,
|
122
90
|
): Promise<[Account, Chain]> {
|
123
91
|
if (options.authResult && connector.loginWithAuthToken) {
|
124
92
|
await connector.loginWithAuthToken(options.authResult);
|
@@ -144,33 +112,6 @@ export async function autoConnectInAppWallet(
|
|
144
112
|
});
|
145
113
|
}
|
146
114
|
|
147
|
-
if (ecosystem) {
|
148
|
-
const ecosystemOptions = await getEcosystemOptions(ecosystem.id);
|
149
|
-
const smartAccountOptions = ecosystemOptions?.smartAccountOptions;
|
150
|
-
if (smartAccountOptions) {
|
151
|
-
const allowedChains = smartAccountOptions.chainIds;
|
152
|
-
const firstAllowedChain = allowedChains[0];
|
153
|
-
if (!firstAllowedChain) {
|
154
|
-
throw new Error(
|
155
|
-
"At least one chain must be allowed for ecosystem smart account",
|
156
|
-
);
|
157
|
-
}
|
158
|
-
const preferredChain =
|
159
|
-
options.chain && allowedChains.includes(options.chain.id)
|
160
|
-
? options.chain
|
161
|
-
: getCachedChain(firstAllowedChain);
|
162
|
-
return convertToSmartAccount({
|
163
|
-
client: options.client,
|
164
|
-
authAccount,
|
165
|
-
smartAccountOptions: {
|
166
|
-
chain: preferredChain,
|
167
|
-
sponsorGas: smartAccountOptions.sponsorGas,
|
168
|
-
factoryAddress: smartAccountOptions.accountFactoryAddress,
|
169
|
-
},
|
170
|
-
});
|
171
|
-
}
|
172
|
-
}
|
173
|
-
|
174
115
|
return [authAccount, options.chain || ethereum] as const;
|
175
116
|
}
|
176
117
|
|
@@ -12,6 +12,7 @@ import type {
|
|
12
12
|
MultiStepAuthArgsType,
|
13
13
|
SingleStepAuthArgsType,
|
14
14
|
} from "../authentication/types.js";
|
15
|
+
import type { UserStatus } from "./enclave-wallet.js";
|
15
16
|
|
16
17
|
export type Ecosystem = {
|
17
18
|
id: EcosystemWalletId;
|
@@ -33,6 +34,8 @@ export type InAppWalletAutoConnectOptions = {
|
|
33
34
|
chain?: Chain;
|
34
35
|
};
|
35
36
|
|
37
|
+
export type WalletUser = UserStatus;
|
38
|
+
|
36
39
|
export type InAppWalletSocialAuth = SocialAuthOption;
|
37
40
|
export type InAppWalletOAuth = OAuthOption;
|
38
41
|
export type InAppWalletAuth = AuthOption;
|