import { Connector } from '../../connectors/Connector' ; import { toBase64 } from '../../utils/data' ; import { Address , KeyInfo , Message , NewAddressType , Signature , SignedMessage } from '../Types' ; export class JsonRpcWalletMethodGroup { private conn : Connector ; constructor ( conn ) { this . conn = conn ; } param type public async new ( type = NewAddressType . SECP256K1 ) { const ret = await this . conn . request ( { method : 'Filecoin.WalletNew' , params : [ type ] } ) ; return ret as string ; } /**
     * get wallet list
     */ public async list ( ) { const ret = await this . conn . request ( { method : 'Filecoin.WalletList' } ) ; return ret as string [ ] ; } param address public async balance ( address ) { const ret = await this . conn . request ( { method : 'Filecoin.WalletBalance' , params : [ address ] } ) ; return ret as string ; } param address public async delete ( address ) { const ret = await this . conn . request ( { method : 'Filecoin.WalletDelete' , params : [ address ] } ) ; return ret as boolean ; } param address public async has ( address ) { const ret = await this . conn . request ( { method : 'Filecoin.WalletHas' , params : [ address ] } ) ; return ret as boolean ; } param address public async setDefault ( address ) { const ret = await this . conn . request ( { method : 'Filecoin.WalletSetDefault' , params : [ address ] } ) ; return ret as undefined ; } param address public async export ( address ) { const ret = await this . conn . request ( { method : 'Filecoin.WalletExport' , params : [ address ] } ) ; return ret as KeyInfo ; } param keyInfo public async import ( keyInfo ) { const ret = await this . conn . request ( { method : 'Filecoin.WalletImport' , params : [ keyInfo ] } ) ; return ret as string ; } /**
     * get default address
     */ public async getDefaultAddress ( ) { const ret = await this . conn . request ( { method : 'Filecoin.WalletDefaultAddress' } ) ; return ret as string ; } param msg public async signMessage ( msg ) { const address = await this . getDefaultAddress ( ) ; const ret = await this . conn . request ( { method : 'Filecoin.WalletSignMessage' , params : [ address , msg ] } ) ; return ret as SignedMessage ; } param data public async sign ( data ) { const address = await this . getDefaultAddress ( ) ; data = toBase64 ( data ) ; const ret = await this . conn . request ( { method : 'Filecoin.WalletSign' , params : [ address , data ] } ) ; return ret as Signature ; } param data param sign public async verify ( address , data , sign ) { data = toBase64 ( data ) ; const ret = await this . conn . request ( { method : 'Filecoin.WalletVerify' , params : [ address , data , sign ] } ) ; return ret as boolean ; } param address public async validateAddress ( address ) { const addressResponse = await this . conn . request ( { method : 'Filecoin.WalletValidateAddress' , params : [ address ] } ) ; return addressResponse ; } }