You can securely export the private key for a WaaS wallet account. On web you specify an HTML element to host an iframe containing the private key; on React Native you mount the <ExportPrivateKey /> component, which hosts the key inside a screenshot-protected native WebView. In every case the key is rendered inside a sandboxed document and never crosses into your application’s JavaScript.
Usage
JavaScript
React
React Native
import { exportWaasPrivateKey, isWaasWalletAccount } from '@dynamic-labs-sdk/client/waas';import { client } from './client';const exportPrivateKey = async () => { const walletAccounts = client.wallets.getWalletAccounts(); const walletAccount = walletAccounts[0]; if (!isWaasWalletAccount({ walletAccount })) return; await exportWaasPrivateKey({ walletAccount, displayContainer: document.getElementById('display-container'), });};// Add a container in your UI to inject the iframe// E.g: <div id="display-container"></div>
Use a ref to pass the DOM element to exportWaasPrivateKey:
On React Native the key is displayed by the <ExportPrivateKey /> component from a dedicated package. It renders the key inside a react-native-webview with screenshot/recording protection enabled, and the key never crosses the JS bridge — your app code cannot read, log, or screenshot it.
npm install @dynamic-labs-sdk/react-native-embedded-wallet-export react-native-webviewcd ios && bundle exec pod install && cd ..
Mount <ExportPrivateKey /> to show the key and unmount it to dismiss — the component owns the display’s lifecycle. Place it inside your own modal or card with a close button.
Exporting a private key is a sensitive action guarded by the wallet:export scope, so the SDK requires an elevated session for the export ceremony. If your environment enforces MFA, the user is prompted to step up before the key is shown. See Step-up authentication.
Props
Prop
Type
Description
walletAccount
WalletAccount
The WaaS wallet account to export. Required.
password
string
Optional password to decrypt the private key.
onComplete
() => void
Fires once the key is displayed. Receives no key material.
onError
(error: unknown) => void
Fires on failure. The error never contains key material.
style
StyleProp<ViewStyle>
Styles the box that hosts the key display; the WebView fills it.
To show a spinner while the key resolves, render your own indicator behind the component (the display is transparent while it loads) and hide it on onComplete. Keep the spinner pointerEvents="none" so it doesn’t intercept taps meant for the key display.
Business Account export approvals
Exporting a Business Account wallet’s key can require approvals from other members, when the wallet’s policy sets a quorum on export. The flow mirrors quorum-gated signing:
The first exportWaasPrivateKey or exportWaasPrivateKeyToContainer call builds the export intent and signs it with the session key automatically. If the policy requires approvals, the call throws a SigningConsentRequiredError with reason: 'APPROVALS_REQUIRED' and a proposalId — and shows no key.
Eligible Business Account members approve the proposal, exactly as for a signing proposal.
Call the export again with that proposalId. The approved proposal already carries its intent, so the export completes without signing a second one.
import { exportWaasPrivateKey, isSigningConsentRequiredError,} from '@dynamic-labs-sdk/client/waas';const exportWithApprovals = async (walletAccount, displayContainer) => { try { await exportWaasPrivateKey({ walletAccount, displayContainer }); } catch (error) { if ( !isSigningConsentRequiredError(error) || error.reason !== 'APPROVALS_REQUIRED' ) { throw error; } // Wait for the proposal to be approved, then export again. await waitForProposalApproval(error.proposalId); await exportWaasPrivateKey({ walletAccount, displayContainer, proposalId: error.proposalId, }); }};
Both functions also accept an approvalQuorum (typed ExportApprovalQuorumRequest) carrying a signed ExportIntent when your app prepares the intent itself; omitting it lets the SDK build and sign one. Personal wallets have no export quorum and ignore these parameters.
Error Handling
If the specified wallet account is not a WaaS WalletAccount, it will throw an NotWaasWalletAccountError error.
If the wallet’s Business Account policy requires approvals to export, it throws a SigningConsentRequiredError with reason: 'APPROVALS_REQUIRED'; see Business Account export approvals.