Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-hounds-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

enable private key export for enclave wallets upon initial login
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@
}}
wallet={activeWallet}
client={client}
connectLocale={locale}

Check warning on line 885 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx#L885

Added line #L885 was not covered by tests
/>
);
} else if (screen === "manage-wallet") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use client";
import { useState } from "react";
import { useEffect, useState } from "react";
import type { ThirdwebClient } from "../../../../../client/client.js";
import { getThirdwebDomains } from "../../../../../utils/domains.js";
import { getThirdwebBaseUrl } from "../../../../../utils/domains.js";
import { webLocalStorage } from "../../../../../utils/storage/webStorage.js";
import { isEcosystemWallet } from "../../../../../wallets/ecosystem/is-ecosystem-wallet.js";
import { ClientScopedStorage } from "../../../../../wallets/in-app/core/authentication/client-scoped-storage.js";
import type { Wallet } from "../../../../../wallets/interfaces/wallet.js";
import type { Theme } from "../../../../core/design-system/index.js";
import { Spacer } from "../../components/Spacer.js";
import { Spinner } from "../../components/Spinner.js";
import { Container, Line, ModalHeader } from "../../components/basic.js";
import type { ConnectLocale } from "../locale/types.js";

/**
* @internal
Expand All @@ -17,13 +20,62 @@
wallet?: Wallet;
theme: "light" | "dark" | Theme;
client: ThirdwebClient;
connectLocale: ConnectLocale;
}) {
const [isLoading, setLoading] = useState(true);
useEffect(() => {
const loginReady = async (e: MessageEvent<{ eventType: string }>) => {
if (
typeof e.data === "object" &&
"eventType" in e.data &&
e.origin === baseDomain
) {
if (e.data.eventType === "exportPrivateKeyIframeLoaded") {
const iframe = document.getElementById(
`export-wallet-${props.wallet?.id}`,
);

Check warning on line 36 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx#L26-L36

Added lines #L26 - L36 were not covered by tests

if (!(iframe instanceof HTMLIFrameElement)) {
return;
}
if (!props.wallet) {
return;
}

Check warning on line 43 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx#L38-L43

Added lines #L38 - L43 were not covered by tests

const clientStorage = new ClientScopedStorage({
clientId: props.client.clientId,
storage: webLocalStorage,
ecosystem: isEcosystemWallet(props.wallet)
? {
id: props.wallet.id,
partnerId: props.wallet.getConfig()?.partnerId,
}
: undefined,
});
if (iframe?.contentWindow) {
iframe.contentWindow.postMessage(
{
eventType: "initExportPrivateKey",
authToken: await clientStorage.getAuthCookie(),
},
e.origin,
);
}
}
}
};
window.addEventListener("message", loginReady);

Check warning on line 67 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx#L45-L67

Added lines #L45 - L67 were not covered by tests

return () => {
window.removeEventListener("message", loginReady);
};
}, [props.wallet, props.client.clientId]);

Check warning on line 72 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx#L69-L72

Added lines #L69 - L72 were not covered by tests

if (!props.wallet) {
throw new Error("[PrivateKey] No wallet found");
}

const baseDomain = getThirdwebDomains().inAppWallet;
const baseDomain = getThirdwebBaseUrl("inAppWallet");

Check warning on line 78 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx#L78

Added line #L78 was not covered by tests
const ecosystem = isEcosystemWallet(props.wallet)
? { id: props.wallet.id, partnerId: props.wallet.getConfig()?.partnerId }
: undefined;
Expand All @@ -35,7 +87,10 @@
}}
>
<Container p="lg">
<ModalHeader title="Export Private Key" onBack={props.onBack} />
<ModalHeader
title={props.connectLocale.manageWallet.exportPrivateKey}
onBack={props.onBack}
/>

Check warning on line 93 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx#L90-L93

Added lines #L90 - L93 were not covered by tests
</Container>
<Line />
<Container
Expand Down Expand Up @@ -68,6 +123,7 @@
}}
>
<iframe
id={`export-wallet-${props.wallet.id}`}

Check warning on line 126 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx#L126

Added line #L126 was not covered by tests
title="Export In-App Wallet"
style={{
width: "100%",
Expand All @@ -78,9 +134,7 @@
setLoading(false);
}}
allow="clipboard-read; clipboard-write"
src={`${
baseDomain.includes("localhost") ? "http" : "https"
}://${baseDomain}/sdk/2022-08-12/embedded-wallet/export-private-key?clientId=${
src={`${baseDomain}/sdk/2022-08-12/embedded-wallet/export-private-key?clientId=${

Check warning on line 137 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx#L137

Added line #L137 was not covered by tests
props.client.clientId
}&theme=${
typeof props.theme === "string" ? props.theme : props.theme.type
Expand Down
Loading