@keccak256-evg/passport-sdk
Version:
T-REX Passport SDK for interacting with Passport and Registry contracts
143 lines (142 loc) • 4.93 kB
TypeScript
import { Account } from "thirdweb/wallets";
import { PassportSDKConfig, WalletPassportResult, PassportInfo, PendingBindRequest, PassportRequest } from "./types";
import { TransactionReceipt } from "thirdweb/transaction";
export interface TransactionOptions {
sendTransaction?: boolean;
account?: Account;
}
export interface TransactionResult {
transactionHash?: string;
receipt?: any;
preparedTransaction?: any;
}
export declare class PassportSDK {
readonly config: PassportSDKConfig;
private viemClient;
private defaultAccount?;
constructor(config: PassportSDKConfig & {
account?: Account;
});
/**
* 验证合约配置是否正确
*/
validateConfiguration(): Promise<{
isValid: boolean;
issues: string[];
}>;
/**
* 创建 Passport
*/
createPassport(request: PassportRequest, signature: `0x${string}`, options?: TransactionOptions): Promise<TransactionReceipt | any>;
/**
* 检查钱包是否有 Passport
*/
checkWalletHasPassport(walletAddress: string): Promise<WalletPassportResult>;
/**
* 获取 Passport 信息
*/
getPassportInfo(passportAddress: string): Promise<PassportInfo>;
/**
* 预测 Passport 地址
*/
predictPassportAddress(walletAddress: string): Promise<string>;
/**
* 获取 Passport 实现地址
*/
getPassportImplementation(): Promise<string>;
/**
* 获取 Passport ID 计数器
*/
getPassportIdCounter(): Promise<number>;
/**
* 通过 Passport ID 获取合约地址
*/
getPassportAddressById(passportId: number): Promise<string>;
/**
* 检查钱包是否被废除
*/
isWalletAbolished(walletAddress: string): Promise<boolean>;
/**
* 检查钱包是否从特定 Passport 解绑
*/
isWalletUnboundFromPassport(passportId: number, walletAddress: string): Promise<boolean>;
/**
* 检查钱包是否有特定 Passport
*/
hasPassport(walletAddress: string, passportContractAddress: string): Promise<boolean>;
/**
* 获取 Passport 当前实现地址
*/
getPassportImplementationAddress(passportAddress: string): Promise<string>;
/**
* 获取 Passport ID
*/
getPassportId(passportAddress: string): Promise<number>;
/**
* 获取 PassportRegistry 合约地址
*/
getRegistryAddress(passportAddress: string): Promise<string>;
/**
* 检查钱包是否绑定到 Passport
*/
isWalletBound(passportAddress: string, walletAddress: string): Promise<boolean>;
/**
* 获取所有绑定钱包
*/
getBoundWallets(passportAddress: string): Promise<readonly string[]>;
/**
* 获取钱包数量
*/
getWalletCount(passportAddress: string): Promise<number>;
/**
* 通过索引获取绑定钱包
*/
getBoundWalletByIndex(passportAddress: string, index: number): Promise<string>;
/**
* 检查是否有待处理绑定请求
*/
hasPendingBindRequest(passportAddress: string, walletAddress: string): Promise<boolean>;
/**
* 取消过期的绑定请求
*/
cancelExpiredBindRequest(passportAddress: string, walletAddress: string, options?: TransactionOptions): Promise<TransactionResult>;
/**
* 解绑钱包
*/
unbindWallet(passportAddress: string, options?: TransactionOptions): Promise<TransactionResult>;
/**
* 请求绑定钱包
*/
requestBindWallet(passportAddress: string, walletAddress: string, options?: TransactionOptions): Promise<TransactionReceipt | any>;
/**
* 获取待处理绑定请求信息
*/
getPendingBindRequest(passportAddress: string, walletAddress: string): Promise<PendingBindRequest>;
/**
* 取消绑定请求
*/
cancelBindRequest(passportAddress: string, walletAddress: string, options?: TransactionOptions): Promise<TransactionResult>;
/**
* 接受绑定请求
*/
acceptBindRequest(passportAddress: string, options?: TransactionOptions): Promise<TransactionReceipt | any>;
/**
* 拒绝绑定请求
*/
rejectBindRequest(passportAddress: string, options?: TransactionOptions): Promise<TransactionResult>;
/**
* 获取待处理绑定钱包列表(使用 viem 确保 msg.sender 验证)
*/
getPendingBindWallets(passportAddress: string, account: string): Promise<readonly string[]>;
/**
* Check if a Passport needs to be upgraded
* @param passportAddress The Passport contract address
* @returns True if upgrade is needed, false otherwise
*/
checkPassportUpgrade(passportAddress: string): Promise<boolean>;
/**
* Upgrade the caller's Passport to the latest implementation
* @returns Prepared transaction for upgrading the Passport
*/
upgradeMyPassport(options?: TransactionOptions): Promise<TransactionResult>;
}