Skip to content

Commit c1008a5

Browse files
authored
[SDK] Feature: Enclave migration (#4684)
1 parent 11a833e commit c1008a5

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

.changeset/proud-files-drop.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+
Migrates existing sharded ecosystem wallets to enclaves

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export type AuthQuerierTypes = {
2828
storedToken: AuthStoredTokenWithCookieReturnType["storedToken"];
2929
recoveryCode?: string;
3030
};
31+
migrateFromShardToEnclave: {
32+
storedToken: AuthStoredTokenWithCookieReturnType["storedToken"];
33+
};
3134
};
3235

3336
/**

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ export class InAppWebConnector implements InAppConnector {
8585
ecosystem,
8686
onAuthSuccess: async (authResult) => {
8787
onAuthSuccess?.(authResult);
88+
89+
if (
90+
this.ecosystem &&
91+
authResult.storedToken.authDetails.walletType === "sharded"
92+
) {
93+
// If this is an existing sharded ecosystem wallet, we'll need to migrate
94+
const result = await this.querier.call<boolean>({
95+
procedureName: "migrateFromShardToEnclave",
96+
params: {
97+
storedToken: authResult.storedToken,
98+
},
99+
});
100+
if (!result) {
101+
throw new Error("Failed to migrate from sharded to enclave wallet");
102+
}
103+
}
104+
88105
await this.initializeWallet(authResult.storedToken.cookieString);
89106

90107
if (!this.wallet) {
@@ -148,6 +165,7 @@ export class InAppWebConnector implements InAppConnector {
148165
"Cannot initialize wallet, this user does not have a wallet generated yet",
149166
);
150167
}
168+
151169
if (user.wallets[0].type === "enclave") {
152170
this.wallet = new EnclaveWallet({
153171
client: this.client,

0 commit comments

Comments
 (0)