import { IdentityKey , IdentityStore } from './' ; import { BasicProfile } from '@ceramicstudio/idx-constants' ; class LocalStorageIdentityStore implements IdentityStore { constructor ( private readonly prefix ) { } async setAddress ( value ) { localStorage . setItem ( this . getKey ( IdentityKey . ADDRESS ) , value ) ; } async getAddress ( ) { return localStorage . getItem ( this . getKey ( IdentityKey . ADDRESS ) ) ; } async setDID ( value ) { localStorage . setItem ( this . getKey ( IdentityKey . DID ) , value ) ; } async getDID ( ) { return localStorage . getItem ( this . getKey ( IdentityKey . DID ) ) ; } async setBasicProfile ( value ) { localStorage . setItem ( this . getKey ( IdentityKey . BASIC_PROFILE ) , JSON . stringify ( value ) ) ; } async getBasicProfile ( ) { const value = localStorage . getItem ( this . getKey ( IdentityKey . BASIC_PROFILE ) ) ; if ( value ) { return JSON . parse ( value ) ; } return null ; } async clearAll ( ) { this . clear ( IdentityKey . ADDRESS ) ; this . clear ( IdentityKey . DID ) ; this . clear ( IdentityKey . BASIC_PROFILE ) ; } async clear ( key ) { localStorage . removeItem ( this . getKey ( key ) ) ; } getKey ( key ) { return `${ this . prefix }:${ key }` ; } } export default LocalStorageIdentityStore ;