Skip to content

Commit 40781b8

Browse files
[SDK] Allow custom chain for SIWE authentication (#8365)
1 parent d907017 commit 40781b8

File tree

8 files changed

+30
-45
lines changed

8 files changed

+30
-45
lines changed

.changeset/loose-moose-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Respect passed chain when doing SIWE for in-app/ecosystem wallet

apps/playground-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"@abstract-foundation/agw-react": "^1.6.4",
3+
"@abstract-foundation/agw-react": "^1.10.0",
44
"@ai-sdk/react": "^2.0.25",
55
"@hookform/resolvers": "^3.9.1",
66
"@radix-ui/react-avatar": "^1.1.10",

packages/thirdweb/src/wallets/in-app/core/authentication/siwe.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { signLoginPayload } from "../../../../auth/core/sign-login-payload.js";
22
import type { LoginPayload } from "../../../../auth/core/types.js";
3+
import type { Chain } from "../../../../chains/types.js";
34
import { getCachedChain } from "../../../../chains/utils.js";
45
import type { ThirdwebClient } from "../../../../client/client.js";
56
import { getClientFetch } from "../../../../utils/fetch.js";
@@ -15,10 +16,11 @@ import type { AuthStoredTokenWithCookieReturnType } from "./types.js";
1516
export async function siweAuthenticate(args: {
1617
wallet: Wallet;
1718
client: ThirdwebClient;
19+
chain?: Chain;
1820
ecosystem?: Ecosystem;
1921
}): Promise<AuthStoredTokenWithCookieReturnType> {
20-
const { wallet, client, ecosystem } = args;
21-
const siweChain = getCachedChain(1); // always use mainnet for SIWE for wide wallet compatibility
22+
const { wallet, client, ecosystem, chain } = args;
23+
const siweChain = chain || getCachedChain(1); // fallback to mainnet for SIWE for wide wallet compatibility
2224
// only connect if the wallet doesn't already have an account
2325
const account =
2426
wallet.getAccount() || (await wallet.connect({ chain: siweChain, client }));

packages/thirdweb/src/wallets/in-app/core/authentication/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export type SingleStepAuthArgsType =
6969
| {
7070
strategy: "wallet";
7171
wallet: Wallet;
72-
chain: Chain;
72+
chain?: Chain;
7373
}
7474
| {
7575
strategy: "guest";

packages/thirdweb/src/wallets/in-app/native/native-connector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export class InAppNativeConnector implements InAppConnector {
186186
client: this.client,
187187
ecosystem: params.ecosystem,
188188
wallet: params.wallet,
189+
chain: params.chain,
189190
});
190191
}
191192
case "github":

packages/thirdweb/src/wallets/in-app/web/lib/web-connector.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ describe("InAppWebConnector.connect", () => {
107107
client: TEST_CLIENT,
108108
ecosystem: undefined,
109109
wallet: mockWallet,
110+
chain: ethereum,
110111
});
111112
});
112113

packages/thirdweb/src/wallets/in-app/web/lib/web-connector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ export class InAppWebConnector implements InAppConnector {
368368
client: this.client,
369369
ecosystem: this.ecosystem,
370370
wallet: args.wallet,
371+
chain: args.chain,
371372
});
372373
}
373374
}

pnpm-lock.yaml

Lines changed: 16 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)