@ 动力- labs- sdk/ 反应- 内嵌- wallet- 导出
为动态 WaaS 嵌入钱包安全私钥导出 原生反应。 。 。 .
导出仪式运行在一个可见,屏幕截图保护的本地 Webview 重叠。 私人密钥完全在WebView的沙盒内制成 文档——它是 永远 所以主机应用程序 JavaScript 无法读取,日志或截取它 。 这是故意的安全 边框:整合 SDK 的开发者无法访问原始密钥.
安装
pnpm add @dynamic-labs-sdk/react-native-embedded-wallet-export
要求数 @dynamic-labs-sdk/client (配置为 React 原住民) 和 a React
连接 DynamicClientWebView 本地模块运出
客户端软件包.
使用量
挂载 <ExportPrivateKey /> 以显示导出覆盖;卸载到
开除 组件拥有覆盖的生命周期.
import { ExportPrivateKey } from '@dynamic-labs-sdk/react-native-embedded-wallet-export';
import { getWalletAccounts } from '@dynamic-labs-sdk/client';
import { isWaasWalletAccount } from '@dynamic-labs-sdk/client/waas';
import { useState } from 'react';
import { Button, View } from 'react-native';
function ExportScreen() {
const [revealing, setRevealing] = useState(false);
const walletAccount = getWalletAccounts()[0];
if (!walletAccount || !isWaasWalletAccount({ walletAccount })) return null;
return (
<View>
<Button title="Reveal private key" onPress={() => setRevealing(true)} />
{revealing && (
<ExportPrivateKey
walletAccount={walletAccount}
onError={(error) => {
// Log a non-sensitive representation only — never the raw error,
// which could carry key material or stack traces.
const errorType = error instanceof Error ? error.name : typeof error;
console.warn('Private key export failed', { errorType });
setRevealing(false);
}}
/>
)}
</View>
);
}
显示装入状态
ExportPrivateKey 是一个最小的原始: 它使安全箱加上
本地覆盖和信号准备通过 onComplete (一旦钥匙响起就开火)
显示). 装入UI是你的风格, 让你自己的旋转器和隐藏
打开 onComplete。本地覆盖在装入时透明,所以
旋转器放在后面 显示在等待期间.
import { ActivityIndicator, StyleSheet, View } from 'react-native';
import { useState } from 'react';
function ExportWithSpinner({ walletAccount }) {
const [loading, setLoading] = useState(true);
return (
<View style={{ position: 'relative' }}>
<ExportPrivateKey
walletAccount={walletAccount}
onComplete={() => setLoading(false)}
onError={() => setLoading(false)}
/>
{loading && (
<View
pointerEvents="none"
style={[
StyleSheet.absoluteFillObject,
{ alignItems: 'center', justifyContent: 'center' },
]}
>
<ActivityIndicator size="large" />
</View>
)}
</View>
);
}
pointerEvents="none" 使旋转器不拦截用于
本地密钥WebView(例如其副本按钮).
道具
| Prop | 类型 | 说明 |
|---|---|---|
walletAccount | WalletAccount | WaaS 钱包账户,其私钥被导出 。 要求. |
password | string | 可选密码来解密私钥. |
onComplete | () => void | 当密钥显示在上方时调用 。 没有关键材料. |
onError | (error: unknown) => void | 要求出口失败。 此错误从未包含密钥材料 . |
警卫
- 密钥只在本地的 WebView 上方显示, 并且从未交叉 jS桥.
- 覆盖可实现截图/记录保护并禁用网络 检查.
- 卸载组件会撕下覆盖, 因此显示的密钥不能 超过屏幕要求它.