import { Component } from "@angular/core" ; import OpenLogin from "openlogin" ; import * as bs58 from "bs58" ; import { getED25519Key } from "@toruslabs/openlogin-ed25519" ; const YOUR_PROJECT_ID = "BOUSb58ft1liq2tSVGafkYohnNPgnl__vAlYSk3JnpfW281kApYsw30BG1-nGpmy8wK-gT3dHw2D_xRXpTEdDBE" ; const openlogin = new OpenLogin ( { clientId : YOUR_PROJECT_ID , network : "testnet" , } ) ; @ Component ( { selector : "app-root" , templateUrl : "./app.component.html" , styleUrls : [ "./app.component.css" ] , } ) export class AppComponent { loading = false ; privKey = "" ; async ngAfterContentInit ( ) { this . loading = true ; try { await openlogin . init ( ) ; this . privKey = openlogin . privKey ; } catch ( error ) { console . log ( "error while initializing" , error ) ; } finally { this . loading = false ; } } async login ( _ ) { this . loading = true ; try { const privKey = await openlogin . login ( { loginProvider : "" , redirectUrl : `${ window . location . origin }` , relogin : true , fastLogin : false , skipTKey : false , } ) ; if ( privKey && typeof privKey === "string" ) { const userInfo = await openlogin . getUserInfo ( ) ; this . printToConsole ( userInfo ) ; } this . loading = false ; } catch ( error ) { console . log ( "error" , error ) ; this . loading = false ; } } getUserInfo = async ( _ ) => { const userInfo = await openlogin . getUserInfo ( ) ; this . printToConsole ( userInfo ) ; } ; getEd25519Key = async ( _ ) => { const { sk } = getED25519Key ( openlogin . privKey ) ; const base58Key = bs58 . encode ( sk ) ; this . printToConsole ( base58Key ) ; } ; logout = async ( _ ) => { this . loading = true ; try { await openlogin . logout ( { } ) ; this . privKey = openlogin . privKey ; } catch ( error ) { this . printToConsole ( "error while logout" , error ) ; } finally { this . loading = false ; } } ; printToConsole = ( ... args ) : void => { const el = document . querySelector ( "#console>p" ) ; if ( el ) { el . innerHTML = JSON . stringify ( args || { } , null , 2 ) ; } } ; }