钱包SDK
This commit is contained in:
@@ -9,6 +9,8 @@ import { WxPlatformSDK } from "./platform/WxPlatformSDK";
|
||||
import { WxAdSDK } from "./ads/WxAdSDK";
|
||||
import { LuffaWalletSDK } from "./wallet/LuffaWalletSDK";
|
||||
import { UmaAnalyticsSDK } from "./analytics/UmaAnalyticsSDK";
|
||||
import { ISignCap } from "./core/ISignCap";
|
||||
import { ITransactionCap } from "./core/ITransactionCap";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -122,12 +124,57 @@ export class SDKManager {
|
||||
|
||||
/** --------------------------------------------------------- 钱包 --------------------------------------------------------- */
|
||||
|
||||
// 连接钱包
|
||||
public connectWallet(cb: (address: string, publicKey?: string) => void): void {
|
||||
if (!this.walletSDK) return;
|
||||
this.walletSDK.connectWallet(cb);
|
||||
}
|
||||
|
||||
// 断开钱包连接
|
||||
public disconnectWallet(): void {
|
||||
if (!this.walletSDK) return;
|
||||
this.walletSDK.disconnectWallet();
|
||||
}
|
||||
|
||||
// 获取当前钱包地址
|
||||
public getWalletAddress(): string | null {
|
||||
if (!this.walletSDK) return null;
|
||||
return this.walletSDK.getWalletAddress()
|
||||
}
|
||||
|
||||
// 签名消息
|
||||
public async signMessage(message: string, options?: any): Promise<{ signature: string; fullMessage?: string }> {
|
||||
if (!this.walletSDK) return;
|
||||
// 判断是否实现签名能力
|
||||
if ("signMessage" in this.walletSDK) {
|
||||
const signer = this.walletSDK as unknown as ISignCap;
|
||||
return signer.signMessage(message, options);
|
||||
}
|
||||
throw new Error("当前钱包 SDK 不支持 signMessage 功能");
|
||||
}
|
||||
|
||||
// 签名交易
|
||||
public async signTransaction(rawData: any): Promise<{ signedData: string }> {
|
||||
if (!this.walletSDK) return;
|
||||
// 判断是否实现交易能力
|
||||
if ("signTransaction" in this.walletSDK) {
|
||||
const txCap = this.walletSDK as unknown as ITransactionCap;
|
||||
return txCap.signTransaction(rawData);
|
||||
}
|
||||
throw new Error("当前钱包 SDK 不支持 signTransaction 功能");
|
||||
}
|
||||
|
||||
// 发送交易(广播到链上)
|
||||
public async sendTransaction(signedData: string): Promise<{ hash: string }> {
|
||||
if (!this.walletSDK) return;
|
||||
// 判断是否实现交易能力
|
||||
if ("sendTransaction" in this.walletSDK) {
|
||||
const txCap = this.walletSDK as unknown as ITransactionCap;
|
||||
return txCap.sendTransaction(signedData);
|
||||
}
|
||||
throw new Error("当前钱包 SDK 不支持 sendTransaction 功能");
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------- 平台基础 --------------------------------------------------------- */
|
||||
|
||||
// 登录
|
||||
|
||||
Reference in New Issue
Block a user