钱包SDK

This commit is contained in:
chen wei bo
2025-09-27 14:04:13 +08:00
parent 6d1a705991
commit 19417f1089
9 changed files with 141 additions and 43 deletions
@@ -0,0 +1,15 @@
/**
* 签名能力接口
* - 提供消息签名功能(常用于登录 / 身份认证)
*/
export interface ISignCap {
/**
* 签名消息
*
* @param message 待签名的消息
* @param options 可选参数(nonce、防重放字段、是否包含链ID等)
* @returns 签名结果
*/
signMessage(message: string, options?: { nonce?: number; [key: string]: any }): Promise<{ signature: string; fullMessage?: string }>;
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "25e17c8e-1f72-4937-81cf-9ecbd2cb664d",
"files": [],
"subMetas": {},
"userData": {}
}
@@ -0,0 +1,22 @@
/**
* 交易能力接口
* - 提供交易签名和广播的能力
*/
export interface ITransactionCap {
/**
* 签名交易(由 DApp 构造交易对象)
*
* @param rawData 原始交易对象
* @returns 已签名交易
*/
signTransaction(rawData: any): Promise<{ signedData: string }>;
/**
* 发送交易(广播到链上)
*
* @param signedData 已签名交易
* @returns 交易哈希
*/
sendTransaction(signedData: string): Promise<{ hash: string }>;
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "930e2711-3254-4f6c-9e8f-be5a565ae0a4",
"files": [],
"subMetas": {},
"userData": {}
}
+5 -16
View File
@@ -1,6 +1,7 @@
/**
* 定义钱包 SDK 的统一接口,用于封装不同平台的钱包接入逻辑(例如 Luffa、MetaMask、Phantom)。
*
* 钱包基础能力接口
* - 只包含连接 / 断开 / 获取地址
* - 更高级的签名、交易能力通过扩展接口实现
*/
import { ISDK } from "./ISDK";
@@ -16,7 +17,7 @@ export interface IWalletSDK extends ISDK {
* - address: 钱包地址(字符串)
* - publicKey?: 钱包公钥(部分钱包可能返回,用于后续签名验证)
*/
connect(cb: (address: string, publicKey?: string) => void): void;
connectWallet(cb: (address: string, publicKey?: string) => void): void;
/**
* 断开钱包连接
@@ -24,7 +25,7 @@ export interface IWalletSDK extends ISDK {
* 清理当前钱包的会话信息(如地址、公钥、缓存的 session)。
* 调用后 getWalletAddress() 应返回 null。
*/
disconnect(): void;
disconnectWallet(): void;
/**
* 获取当前钱包地址
@@ -33,16 +34,4 @@ export interface IWalletSDK extends ISDK {
* 如果尚未连接,则返回 null。
*/
getWalletAddress(): string | null;
//
signMessage(message: string, nonce: number, options?: any): Promise<any>;
//
buildTransaction(payload: any): Promise<any>;
//
signTransaction(rawData: any): Promise<any>;
//
sendTransaction(signedData: any): Promise<{ hash: string }>;
}