import { StringifiedType , TorusServiceProviderArgs } from "@tkey/common-types" ; import { ServiceProviderBase } from "@tkey/service-provider-base" ; import DirectWebSDK , { AggregateLoginParams , CustomAuthArgs , HybridAggregateLoginParams , InitParams , SubVerifierDetails , TorusAggregateLoginResponse , TorusHybridAggregateLoginResponse , TorusLoginResponse , } from "@toruslabs/customauth" ; import BN from "bn.js" ; class TorusServiceProvider extends ServiceProviderBase { directWeb : DirectWebSDK ; singleLoginKey : BN ; directParams : CustomAuthArgs ; serviceProviderName : string ; constructor ( { enableLogging = false , postboxKey , directParams } ) { super ( { enableLogging , postboxKey } ) ; this . directParams = directParams ; this . directWeb = new DirectWebSDK ( directParams ) ; this . serviceProviderName = "TorusServiceProvider" ; } static fromJSON ( value ) { const { enableLogging , postboxKey , directParams , serviceProviderName } = value ; if ( serviceProviderName !== "TorusServiceProvider" ) return undefined ; return new TorusServiceProvider ( { enableLogging , postboxKey , directParams , } ) ; } async init ( params ) { return this . directWeb . init ( params ) ; } async triggerLogin ( params ) { const obj = await this . directWeb . triggerLogin ( params ) ; this . postboxKey = new BN ( obj . privateKey , "hex" ) ; return obj ; } async triggerAggregateLogin ( params ) { const obj = await this . directWeb . triggerAggregateLogin ( params ) ; this . postboxKey = new BN ( obj . privateKey , "hex" ) ; return obj ; } async triggerHybridAggregateLogin ( params ) { const obj = await this . directWeb . triggerHybridAggregateLogin ( params ) ; const aggregateLoginKey = obj . aggregateLogins [ 0 ] . privateKey ; this . postboxKey = new BN ( aggregateLoginKey , "hex" ) ; this . singleLoginKey = new BN ( obj . singleLogin . privateKey , "hex" ) ; return obj ; } toJSON ( ) { return { ... super . toJSON ( ) , serviceProviderName : this . serviceProviderName , directParams : this . directParams , } ; } } export default TorusServiceProvider ;