Skip to content

Commit

Permalink
added config for store vault and signing modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwas1 committed Jul 10, 2024
1 parent c0a219d commit c8ba8bc
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 60 deletions.
15 changes: 15 additions & 0 deletions src/store/signin/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const storePrefix = 'signin.'
export default {
LOCAL_STATES: {
SSI_ACCESS_TOKEN: `${storePrefix}ssiAccessToken`,
KYC_ACCESS_TOKEN: `${storePrefix}cavachAccessToken`,
REDIRECT_URL: `${storePrefix}redirectUrl`,
AUTHORIZATION: `${storePrefix}authorization`,
PROFILE: `${storePrefix}profile`,
SUBDOMAIN: `${storePrefix}subdomain`,
SESSIONS: `${storePrefix}session`,
PR: `${storePrefix}presentationRequest`,
WIDGET_CONFIG: `${storePrefix}widgetConfigFromDb`,
ON_CHAIN_CONFIG: `${storePrefix}onChainIssuerConfig`,
}
}
27 changes: 12 additions & 15 deletions src/store/signin/getters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HYPERSIGN_SERVICE_BASE_URL_FORMAT } from '../../config'
import SignStoreConfig from './config'
export default {
getActiveStep: (state) => {
const step = state.steps.find(x => {
Expand All @@ -10,48 +11,44 @@ export default {
},
//-----------------------------------------------------------------e-kyc
getSession() {
return localStorage.getItem("session")
return localStorage.getItem(SignStoreConfig.LOCAL_STATES.SESSIONS)
},
getCavachAccessToken() {
return localStorage.getItem("cavachAccessToken")
return localStorage.getItem(SignStoreConfig.LOCAL_STATES.KYC_ACCESS_TOKEN)
},
getRedirectUrl() {
return localStorage.getItem("redirectUrl")
return localStorage.getItem(SignStoreConfig.LOCAL_STATES.REDIRECT_URL)
},
getAuthServerAuthToken() {
return localStorage.getItem("authServerAuthToken")
},

getProfile() {
const profileStr = localStorage.getItem('profile')
const profileStr = localStorage.getItem(SignStoreConfig.LOCAL_STATES.PROFILE)
if (profileStr) {
return JSON.parse(profileStr)
} else {
return null
}
},
getSSIAccessToken() {
return localStorage.getItem("ssiAccessToken")
return localStorage.getItem(SignStoreConfig.LOCAL_STATES.SSI_ACCESS_TOKEN)
},

getTenantSubdomain() {
return localStorage.getItem('subdomain');
return localStorage.getItem(SignStoreConfig.LOCAL_STATES.SUBDOMAIN);
},

getTenantKycServiceBaseUrl() {
const subdomain = localStorage.getItem('subdomain');
const subdomain = localStorage.getItem(SignStoreConfig.LOCAL_STATES.SUBDOMAIN);
if (!subdomain) {
throw new Error('Invalid accessToken')
}
return HYPERSIGN_SERVICE_BASE_URL_FORMAT.replace('<subdomain>', subdomain)
},

getPresentationRequest() {
return localStorage.getItem("presentationRequest")
return localStorage.getItem(SignStoreConfig.LOCAL_STATES.PR)
},

getPresentationRequestParsed() {
const base64EncodedPr = localStorage.getItem("presentationRequest")
const base64EncodedPr = localStorage.getItem(SignStoreConfig.LOCAL_STATES.PR)
const prStr = atob(base64EncodedPr)
return JSON.parse(prStr)
},
Expand All @@ -61,7 +58,7 @@ export default {
},

getOnChainIssuerConfig: () => {
const t = localStorage.getItem("onChainIssuerConfig")
const t = localStorage.getItem(SignStoreConfig.LOCAL_STATES.ON_CHAIN_CONFIG)
if (t) {
return JSON.parse(t)
} else {
Expand All @@ -70,7 +67,7 @@ export default {
},
getWidgetConfigFromDb: (state) => {
console.log(state.hasKycDone)
const t = localStorage.getItem('widgetConfigFromDb');
const t = localStorage.getItem(SignStoreConfig.LOCAL_STATES.WIDGET_CONFIG);
if (t) {
return JSON.parse(t)
} else {
Expand Down
52 changes: 27 additions & 25 deletions src/store/signin/mutations.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@

import SignStoreConfig from './config'
import VaultStoreConfig from '../vault/config'

export default {
clearAllLocalStore() {
localStorage.removeItem('vaultDataRaw');
localStorage.removeItem('mb-user-id');
localStorage.removeItem('profile');
localStorage.removeItem('vaultData');
localStorage.removeItem('authServerAuthToken');
localStorage.removeItem('vaultLockStatus');
localStorage.removeItem('vaultLockStatus');
localStorage.removeItem('vaultPin');
localStorage.removeItem('onChainIssuerConfig');
localStorage.removeItem(SignStoreConfig.LOCAL_STATES.PROFILE);
localStorage.removeItem(SignStoreConfig.LOCAL_STATES.AUTH_SERVER_TOKEN);
localStorage.removeItem(SignStoreConfig.LOCAL_STATES.ON_CHAIN_CONFIG);



// move these in store/vault module
localStorage.removeItem(VaultStoreConfig.LOCAL_STATES.VAULT_DATA_RAW);
localStorage.removeItem(VaultStoreConfig.LOCAL_STATES.VAULT_DATA);
localStorage.removeItem(VaultStoreConfig.LOCAL_STATES.VAULT_LOCK);
localStorage.removeItem('vault.vaultPin');
},



setOnChainIssuerConfig: (state, payload) => {
console.log(state.hasKycDone)
localStorage.setItem("onChainIssuerConfig", JSON.stringify(payload))
localStorage.setItem(SignStoreConfig.LOCAL_STATES.ON_CHAIN_CONFIG, JSON.stringify(payload))
},
setCosmosConnection: (state, payload) => {
state.cosmosConnection = { ...payload };
Expand Down Expand Up @@ -65,32 +72,32 @@ export default {
},
setAuthorization: (state, authorization) => {
state.authorization = authorization
localStorage.setItem('authorization', authorization)
localStorage.setItem(SignStoreConfig.LOCAL_STATES.AUTHORIZATION, authorization)

},

setSession(state, payload) {
console.log(state.hasKycDone)
localStorage.setItem("session", payload)
localStorage.setItem(SignStoreConfig.LOCAL_STATES.SESSIONS, payload)
},

setCavachAccessToken(state, payload) {
console.log(state.kycCapturedData)
localStorage.setItem("cavachAccessToken", payload)
console.log(`Inside setCavachAccessToken ${SignStoreConfig.LOCAL_STATES.KYC_ACCESS_TOKEN} = ${payload}`)
localStorage.setItem(SignStoreConfig.LOCAL_STATES.KYC_ACCESS_TOKEN, payload)
},
setRedirectUrl(state, payload) {
console.log(state.kycCapturedData)
localStorage.setItem("redirectUrl", payload)
localStorage.setItem(SignStoreConfig.LOCAL_STATES.REDIRECT_URL, payload)
},
setPresentationRequest(state, payload) {
console.log(state.kycCapturedData)
localStorage.setItem("presentationRequest", payload)
localStorage.setItem(SignStoreConfig.LOCAL_STATES.PR, payload)
},

setSSIAccessToken(state, payload) {
console.log(state.kycCapturedData)

localStorage.setItem("ssiAccessToken", payload)
localStorage.setItem(SignStoreConfig.LOCAL_STATES.SSI_ACCESS_TOKEN, payload)
},

setThridPartyAuth(state, payload) {
Expand All @@ -99,22 +106,17 @@ export default {

setProfile(state, payload) {
console.log(state.hasKycDone)
localStorage.setItem('profile', JSON.stringify(payload))
},

setAuthServerAuthToken(state, payload) {
console.log(state.hasKycDone)
localStorage.setItem("authServerAuthToken", payload)
localStorage.setItem(SignStoreConfig.LOCAL_STATES.PROFILE, JSON.stringify(payload))
},

setAsNewUser(state, payload) {
console.log(state.hasKycDone)
console.log(`Inside setAsNewUser ${state.hasKycDone}`)
state.ifNewUser = payload;
},

setTenantSubdomain(state, payload) {
console.log(state.hasKycDone)
localStorage.setItem('subdomain', payload);
localStorage.setItem(SignStoreConfig.LOCAL_STATES.SUBDOMAIN, payload);
},

setIdDocumentLicenseKey(state, payload) {
Expand All @@ -123,7 +125,7 @@ export default {

setWidgetConfigFromDb: (state, payload) => {
// state.widgetConfigFromDb = { ...payload }
localStorage.setItem('widgetConfigFromDb', JSON.stringify(payload));
localStorage.setItem(SignStoreConfig.LOCAL_STATES.WIDGET_CONFIG, JSON.stringify(payload));
},


Expand Down
8 changes: 4 additions & 4 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ export default new Vuex.Store({
...vaultState
},
getters: {
...ekycGetters,
...signinGetters,
...vaultGetters,
...ekycGetters,
},
mutations: {
...oldEkycMutations,
...vaultMutations,
...signinMutations,
...oldEkycMutations,
...ekycMutations,
...vaultMutations,
},
actions: {
...oldEkycActions,
...vaultActions,
...signinActions,
...ekycActions,
...vaultActions,
},
})
12 changes: 8 additions & 4 deletions src/store/vault/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { decrypt, encrypt } from '../../components/utils/symmetricCrypto'
// import { RequestHandler } from '../../components/utils/utils';
import SignInStoreConfig from '../signin/config'
const VAULT_SERVER_BASE_URL = 'https://authserver.hypersign.id/hs/api/v2'


import VaultConfig from './config'

export default {
// ---------------------------------------------------------------- EDV (auth server)
registerUser: ({ commit, getters }) => {
Expand Down Expand Up @@ -37,7 +42,6 @@ export default {
commit('setAsNewUser', false)
} else {
commit('setAsNewUser', true)

}

commit('setAuthServerAuthToken', json.authToken)
Expand All @@ -56,7 +60,7 @@ export default {
return reject(new Error('Invalid email, or user is not logged in'))
}

if (!localStorage.getItem('vaultData')) {
if (!localStorage.getItem(VaultConfig.LOCAL_STATES.VAULT_DATA)) {
return reject(new Error('Invalid vault data'))
}
// const url = `${VAULT_SERVER_BASE_URL}/sync/` + email
Expand All @@ -78,7 +82,7 @@ export default {
// "nameSpace": "hypersign-kyc"
},
"document": {
"encryptedMessage": localStorage.getItem('vaultData')
"encryptedMessage": localStorage.getItem(VaultConfig.LOCAL_STATES.VAULT_DATA)
}
})
})
Expand All @@ -99,7 +103,7 @@ export default {

syncUserDataById: ({ getters, commit }) => {
return new Promise((resolve, reject) => {
const { email } = JSON.parse(localStorage.getItem('profile'))
const { email } = JSON.parse(localStorage.getItem(SignInStoreConfig.LOCAL_STATES.PROFILE))
if (!email) {
return reject(new Error('Invalid email, or user is not logged in'))
}
Expand Down
9 changes: 9 additions & 0 deletions src/store/vault/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const storePrefix = 'vault.'
export default {
LOCAL_STATES: {
VAULT_LOCK: `${storePrefix}vaultLockStatus`,
VAULT_DATA: `${storePrefix}vaultData`,
VAULT_DATA_RAW: `${storePrefix}vaultDataRaw`,
AUTH_SERVER_TOKEN: `${storePrefix}authServerAuthToken`,
}
}
16 changes: 11 additions & 5 deletions src/store/vault/getters.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import VaultConfig from './config'

export default {
getVaultPin(state) {
return state.vaultPin;
// return localStorage.getItem('vaultPin')
},
getVaultLockStatus() {
return localStorage.getItem('vaultLockStatus')
return localStorage.getItem(VaultConfig.LOCAL_STATES.VAULT_LOCK)
},
getVaultData() {
return localStorage.getItem('vaultData')
return localStorage.getItem(VaultConfig.LOCAL_STATES.VAULT_DATA)
},
getVaultDataRaw() {
const vaultDataRawStr = localStorage.getItem('vaultDataRaw')
const vaultDataRawStr = localStorage.getItem(VaultConfig.LOCAL_STATES.VAULT_DATA_RAW)
return JSON.parse(vaultDataRawStr)
},

getAuthServerAuthToken() {
return localStorage.getItem(VaultConfig.LOCAL_STATES.AUTH_SERVER_TOKEN)
},

getVaultDataCredentials() {
const vaultDataRawStr = localStorage.getItem('vaultDataRaw')
const vaultDataRawStr = localStorage.getItem(VaultConfig.LOCAL_STATES.VAULT_DATA_RAW)
const vaultDataRaw = JSON.parse(vaultDataRawStr)
const { hypersign } = vaultDataRaw
const { credentials } = hypersign
Expand All @@ -24,7 +30,7 @@ export default {

getUserDID() {
// TODO check if user vault is unlocked
const vaultDataRawStr = localStorage.getItem('vaultDataRaw')
const vaultDataRawStr = localStorage.getItem(VaultConfig.LOCAL_STATES.VAULT_DATA_RAW)
if (vaultDataRawStr) {
const vaultDataRaw = JSON.parse(vaultDataRawStr)

Expand Down
18 changes: 11 additions & 7 deletions src/store/vault/mutations.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import VaultConfig from './config'
export default {
clearVaultPin() {
localStorage.setItem('vaultLockStatus', false)
localStorage.removeItem('vaultPin')
localStorage.setItem(VaultConfig.LOCAL_STATES.VAULT_LOCK, false)

},
setVaultPin(state, payload) {
// console.log(state.hasKycDone)
// localStorage.setItem('vaultPin', payload)
state.vaultPin = payload;
},

setVaultData(state, payload) {
console.log(state.hasKycDone)
localStorage.setItem('vaultData', payload)
localStorage.setItem(VaultConfig.LOCAL_STATES.VAULT_DATA, payload)
},

setAuthServerAuthToken(state, payload) {
console.log(state.hasKycDone)
localStorage.setItem(VaultConfig.LOCAL_STATES.AUTH_SERVER_TOKEN, payload)
},

setVaultRaw(state, payload) {
console.log(state.hasKycDone)
localStorage.setItem('vaultDataRaw', payload)
localStorage.setItem(VaultConfig.LOCAL_STATES.VAULT_DATA_RAW, payload)
},

setVaultLockStatus(state, payload) {
console.log(state.hasKycDone)
localStorage.setItem('vaultLockStatus', payload)
localStorage.setItem(VaultConfig.LOCAL_STATES.VAULT_LOCK, payload)
},

}

0 comments on commit c8ba8bc

Please sign in to comment.