import { MediatorResponse } from "./MediatorInterface" ; import { NetworkServices } from "../../network" ; import { RecordType } from '../../utils/Helpers' ; import { WalletRecord } from '../../wallet/WalletInterface' ; import DatabaseServices from "../../storage" ; import WalletStorageService from '../../wallet/WalletStorageService' ; class MediatorService { param { string } url param { string } apiType param { string } apiBody return { * } memberof async ConnectWithMediator ( url , apiType , apiBody ) { try { const { data : { routingKeys , serviceEndpoint } } = await NetworkServices ( url , apiType , apiBody ) ; const myWallet = DatabaseServices . getWallet ( ) ; DatabaseServices . storeWallet ( { walletConfig : myWallet . walletConfig , walletCredentials : myWallet . credentialsJson , label : myWallet . label , serviceEndpoint : serviceEndpoint , routingKey : routingKeys [ 0 ] , publicDid : myWallet . publicDid , verKey : myWallet . verKey , masterSecretId : myWallet . masterSecretId , } ) ; const walletRecord = { walletConfig : myWallet . walletConfig , walletCredentials : myWallet . credentialsJson , label : myWallet . label , serviceEndpoint : serviceEndpoint , routingKey : routingKeys [ 0 ] , publicDid : myWallet . publicDid , verKey : myWallet . verKey , masterSecretId : myWallet . masterSecretId , } ; await WalletStorageService . updateWalletRecord ( myWallet . walletConfig , myWallet . walletConfig , RecordType . MediatorAgent , '1' , JSON . stringify ( walletRecord ) , '{}' ) ; return Promise . resolve ( true ) ; } catch ( error ) { console . log ( 'MediatorService - Connect with mediator error = ' , error ) ; throw error ; } } param { string } url param { string } apiType param { string } apiBody return { * } memberof async updateMediator ( url , apiType , apiBody ) { try { await NetworkServices ( url , apiType , apiBody ) ; return Promise . resolve ( true ) ; } catch ( error ) { console . log ( 'MediatorService - Update mediator error = ' , error ) ; return Promise . reject ( error ) ; } } } export default new MediatorService ( ) ;