@d-sports/wallet (英语)
请慎用.
一个强大的多平台钱包 SDK 用于 React, Next.js 和 React Indust 应用程序 免费、自定义的社会登录 并且支持"彩虹"和"瓦格米" 100%的D-体育品牌没有供应商依赖.
* 特性
- 🌐 多平台支持: 与 React 、 Next.js 和 React 本地公司合作
- 🔐 自定义社会登录:FREE OAuth与Google,Facebook,Twitter,Discord,GitHub和苹果的集成
- 🏆 D-体育品牌: 完全定制,没有供应商锁定
- 🌈 彩虹套装兼容: 与 Rainbow Kit 钱包连接 UI 的简单集成
- ⚡ Wagmi 兼容: 全力支持 Wagmi v1 和 v2
- 🎨 自定义 UI: 弹性主题和型式选项
- 🔒 安全存储: 平台专用安全存储解决方案
- 📱 移动第一: 深度链接和移动优化经验
- 🔄 自动重联: 会话间持续钱包连接
- 💰 零成本: 不向每个用户收费或外部依赖性
- 🎯 类型脚本: 包含全面类型定义的完整类型脚本支持
* 安装
npm install @d-sports/wallet
# or
yarn add @d-sports/wallet
# or
bun add @d-sports/wallet
平台特有的依赖
下个.js/反应:
# No additional dependencies required!
反应原生 :
npm install react-native-keychain react-native-url-polyfill
QQ 快速启动
超级快起步(5分钟)
立即开始 D-体育管理 OAuth 证书 - 不需要OAuth设置!
import { createDSportsWalletQuickStart, mainnet, polygon } from '@d-sports/wallet';
// 🎉 ONE LINE SETUP - No OAuth configuration needed!
const wallet = createDSportsWalletQuickStart({
projectId: 'your-project-id',
chains: [mainnet, polygon],
metadata: {
name: 'My Awesome App',
description: 'Built with D-Sports Wallet',
url: 'https://my-app.com',
icons: ['https://my-app.com/icon.png']
}
});
// Connect with social login (Google, Facebook, Twitter, Discord, GitHub ready!)
await wallet.connect({ socialLogin: true });
console.log('🎊 Wallet connected with zero OAuth setup!');
完美为:
- 🧪 原型制作 概念的证明
- 👨💻 发展 测试
- 🎓 学习 和辅导
- 🏁 开始 快点
生产设置
对于生产应用,设置自己的 OAuth 应用程序:
下一个.js
import { createDSportsWallet } from '@d-sports/wallet/nextjs';
// Create wallet instance
const wallet = createDSportsWallet({
projectId: 'your-project-id',
chains: [/* your chains */],
environment: 'production', // Validates production config
socialLogin: {
appSecret: 'your-app-secret', // For deterministic key generation
redirectUri: 'https://your-app.com/auth/callback',
providers: {
google: {
clientId: 'your-google-client-id',
},
facebook: {
clientId: 'your-facebook-app-id',
},
twitter: {
clientId: 'your-twitter-client-id',
},
discord: {
clientId: 'your-discord-client-id',
},
},
},
});
// Connect wallet
await wallet.connect();
原生反应
import { createDSportsWallet, setupURLPolyfill } from '@d-sports/wallet/react-native';
// Setup URL polyfill (required for React Native)
setupURLPolyfill();
// Create wallet instance
const wallet = createDSportsWallet({
projectId: 'your-project-id',
chains: [/* your chains */],
socialLogin: {
appSecret: 'your-app-secret',
redirectUri: 'dsports://auth/callback', // Deep link for mobile
providers: {
google: {
clientId: 'your-google-client-id',
},
apple: {
clientId: 'your-apple-client-id',
},
},
},
});
// Connect wallet
await wallet.connect();
使用实例
基本钱包连接
import { createDSportsWallet } from '@d-sports/wallet';
const wallet = createDSportsWallet({
projectId: 'your-project-id',
chains: [
{
id: 1,
name: 'Ethereum',
network: 'homestead',
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
rpcUrls: {
default: { http: ['https://mainnet.infura.io/v3/your-key'] },
public: { http: ['https://mainnet.infura.io/v3/your-key'] }
}
}
]
});
// Connect to wallet
const account = await wallet.connect();
console.log('Connected account:', account);
// Get wallet state
const state = wallet.getState();
console.log('Wallet state:', state);
// Switch chain
await wallet.switchChain(137); // Polygon
// Disconnect
await wallet.disconnect();
自定义社会登录
import { createDSportsWallet, CustomSocialLoginProvider } from '@d-sports/wallet';
const wallet = createDSportsWallet({
projectId: 'your-project-id',
chains: [/* your chains */],
socialLogin: {
appSecret: 'your-unique-app-secret', // Used for deterministic key generation
redirectUri: 'https://your-app.com/auth/callback',
providers: {
google: {
clientId: 'your-google-oauth-client-id',
},
facebook: {
clientId: 'your-facebook-app-id',
},
twitter: {
clientId: 'your-twitter-oauth-client-id',
},
discord: {
clientId: 'your-discord-oauth-client-id',
},
github: {
clientId: 'your-github-oauth-client-id',
},
},
},
});
// Connect with social login
await wallet.connect({ socialLogin: true });
// Get social login provider
const socialProvider = wallet.getConnector('dsports-wallet').customSocialLoginProvider;
// Login with specific provider
const result = await socialProvider.login('google');
console.log('Social login result:', result);
// Get wallet from social login
const ethersWallet = await socialProvider.getWalletFromSocial(result);
console.log('Generated wallet address:', ethersWallet.address);
彩虹套装集成
import { createDSportsRainbowKitConnector } from '@d-sports/wallet';
const connector = createDSportsRainbowKitConnector({
chains: [/* your chains */],
projectId: 'your-project-id',
appName: 'My App',
socialLogin: {
appSecret: 'your-app-secret',
redirectUri: 'https://your-app.com/auth/callback',
providers: {
google: {
clientId: 'your-google-client-id',
},
facebook: {
clientId: 'your-facebook-client-id',
},
},
},
});
// Use with Rainbow Kit
const connectors = [
connector,
// ... other connectors
];
瓦格米融合组织
import { dsportsWagmiConnector } from '@d-sports/wallet';
const connector = dsportsWagmiConnector({
chains: [/* your chains */],
projectId: 'your-project-id',
socialLogin: {
appSecret: 'your-app-secret',
redirectUri: 'https://your-app.com/auth/callback',
providers: {
google: {
clientId: 'your-google-client-id',
},
},
},
});
// Use with Wagmi
const connectors = [
connector,
// ... other connectors
];
API 参考
DSports 钱包
构造选项
interface DSportsWalletOptions {
projectId: string;
chains: Chain[];
socialLogin?: CustomSocialLoginConfig;
theme?: WalletTheme;
metadata?: {
name: string;
description: string;
url: string;
icons: string[];
};
}
方法
connect(config?: { socialLogin?: boolean }): Promise<WalletAccount>disconnect(): Promise<void>switchChain(chainId: number): Promise<void>getState(): WalletStateisConnected(): booleangetConnector(id: string): WalletConnector | undefinedaddConnector(connector: WalletConnector): voidremoveConnector(id: string): void
活动
connect: 钱包连接时发送disconnect: 钱包断开时发送accountsChanged: 账户变更时汇出chainChanged: 当链条改变时发出error: 发生错误时发出
反应钩
使用 DSports 钱包
const {
account,
isConnecting,
isReconnecting,
isDisconnected,
error,
connect,
disconnect,
switchChain,
isConnected
} = useDSportsWallet(wallet);
使用社会记录
const {
user,
isLoading,
error,
login,
logout
} = useSocialLogin(customSocialLoginProvider);
QQ 配置
自定义社会登录配置
interface CustomSocialLoginConfig {
appSecret?: string; // Used for deterministic wallet generation
redirectUri?: string; // OAuth callback URL
providers: {
[key in SocialProvider]?: {
clientId: string;
clientSecret?: string; // For backend token exchange
};
};
}
支助社会提供者
- 谷歌 (单位:千美元)
google: OAuth 2.0 (英语) - 脸书 (单位:千美元)
facebook: Facebook 登录 - 微博 (单位:千美元)
twitter: OAuth 2.0 (英语) - 解析器 (单位:千美元)
discord: OAuth 2.0 (英语) - GitHub 图像 (单位:千美元)
github: OAuth 2.0 (英语) - 苹果公司 (单位:千美元)
apple: 与苹果公司签约
设置 OAuth 应用程序
谷歌 OAuth 设置
- 转到 谷歌云控台
- 创建新工程或选择已有项目
- 启用 Google+ API
- 创建 OAuth 2. 0 证书
- 将您的域添加到授权的起源
- 复制 客户身份
Facebook OAuth 设置
- 转到 Facebook 开发者
- 创建新应用程序
- 设置 Facebook 登录
- 将您的域添加到有效的 OAuth 重定向 URI
- 复制 应用标识
Twitter OAuth 设置
- 转到 Twitter 开发者门户网站
- 创建新应用程序
- 设置 OAuth 2. 0
- 配置回调 URL
- 复制 客户身份
主题配置
interface WalletTheme {
colors?: {
primary?: string;
secondary?: string;
background?: string;
text?: string;
border?: string;
};
borderRadius?: number;
fontFamily?: string;
}
OAuth 回调页面
在您创建回调页面 redirectUri 处理 OAuth 回复:
<!DOCTYPE html>
<html>
<head>
<title>D-Sports Authentication</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; padding: 50px; }
.loading { color: #666; }
.logo { width: 64px; height: 64px; margin: 20px auto; }
</style>
</head>
<body>
<div class="logo">🏆</div>
<h2>D-Sports Authentication</h2>
<p class="loading">Processing your login...</p>
<script>
// Handle OAuth callback
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
const error = urlParams.get('error');
if (error) {
window.parent.postMessage({
type: 'OAUTH_ERROR',
error: error
}, window.location.origin);
} else if (code) {
// Exchange code for user data (implement your backend logic)
window.parent.postMessage({
type: 'OAUTH_SUCCESS',
payload: {
code,
user: {
id: 'user-id-from-your-backend',
email: '[email protected]',
name: 'User Name',
avatar: 'https://example.com/avatar.jpg'
},
token: 'access-token-from-your-backend',
expiresAt: Date.now() + 3600000
}
}, window.location.origin);
}
</script>
</body>
</html>
深链接( 反应原生)
import { handleDeepLink } from '@d-sports/wallet/react-native';
// Handle deep link
handleDeepLink('dsports://wallet/connect?connector=dsports-wallet', wallet);
费用比较
| 提供者 | 费用 | 锁定 | 标记 |
|---|---|---|---|
| @d-sports/wallet (英语) | 自由主义 | 无 | 完全D运动 |
| Web3 认证 | 0.05/MAU美元 | 对 | 有限 |
| 魔术 | 0.02/毛利美元 | 对 | 有限 |
| 枢密院 | 0.05/MAU美元 | 对 | 有限 |
发展
设置
git clone https://github.com/D-Sports-Ecosystem/wallet.git
cd wallet
bun install
构建
bun run build
测试
bun test
开发脚本
bun run dev: 启动开发模式bun run build: 构建所有软件包bun run build:core: 构建核心软件包bun run build:nextjs: 构建下一个.js 软件包bun run build:react-native: 构建本地反应软件包bun run clean: 清洁的建筑文物bun run lint: 运行 ESLintbun run test: 运行测试bun run test:watch: 在监视模式下运行测试
QQ 软件包结构
@d-sports/wallet/
├── core # Core wallet functionality
├── nextjs # Next.js specific exports
├── react-native # React Native specific exports
├── custom-social-login # Custom social login provider
└── types # TypeScript type definitions
安全特性
- 决定密钥生成: 钱包是由社会登录数据决定性生成的
- 安全存储: 平台专用安全存储(localStorage, AsyncStorage, Keychain)
- 无私钥传输: 密钥是本地生成的, 从未发送到服务器
- 自定义应用程序机密: 使用你自己的秘密来增加安全性
- OAuth 最佳做法: 遵循 OAuth 2.0 安全准则
捐款
- 叉子存储器
- 创建您的特性分支( E)
git checkout -b feature/amazing-feature(中文(简体) ) - 提交更改( E)
git commit -m 'Add some amazing feature'(中文(简体) ) - 推向分行(
git push origin feature/amazing-feature(中文(简体) ) - 打开拉请求
许可证
麻省理工学院的执照 - 看 自由主义 详细文件.
承认
由D体育队制作 - 一个免费、开源的替代物,取代昂贵的钱包提供者.
快速启动 生产迁移
发展到生产道路
-
从快速启动开始 (5分钟):
const wallet = createDSportsWalletQuickStart({ projectId: 'your-project-id', chains: [mainnet, polygon] }); -
创建您的 OAuth 应用程序 (30分钟):
-
切换到生产配置数字 :
const wallet = createDSportsWallet({ projectId: 'your-project-id', chains: [mainnet, polygon], environment: 'production', // Validates config socialLogin: { appSecret: 'your-production-secret', redirectUri: 'https://your-app.com/auth/callback', providers: { google: { clientId: 'your-google-client-id' }, facebook: { clientId: 'your-facebook-app-id' }, // ... other providers } } });
D- 体育 OAuth 服务
D-体育 oAuth 证书 用于即时开发:
import { DSportsOAuthService, createQuickStartSocialLogin } from '@d-sports/wallet';
// Get managed credentials
const managed = DSportsOAuthService.getManagedCredentials({
environment: 'development'
});
// Quick start config (auto-generated)
const quickStartConfig = createQuickStartSocialLogin();
// Validate production config
const productionConfig = validateSocialLoginConfig(myConfig, 'production');
管理的OAuth包括:
- ✅ 谷歌 - 准备使用
- ✅ 脸书 - 准备使用
- ✅ 微博 - 准备使用
- ✅ 解析器 - 准备使用
- ✅ GitHub 图像 - 准备使用
- ⚠️ 苹果公司 - 需要个人设置
福利:
- 🚀 即时设置 - 没有 OAuth 配置
- 🛡️ 生产警告 - 自动验证
- 🔄 易行移徙 - 相同的API,不同的配置
- 📚 适合演示 - 立即显示特性