|
| 1 | +import { polykeyClient } from '@/store/PolyKeyClientMock' |
| 2 | + |
1 | 3 | export default { |
2 | 4 | namespaced: true, |
3 | | - state: {}, |
4 | | - actions: {}, |
5 | | - mutations: {}, |
| 5 | + state: { |
| 6 | + publicKey: '', |
| 7 | + privateKey: '', |
| 8 | + keyNames: [], |
| 9 | + selectedKeyName: '', |
| 10 | + selectedKeyContent: '' |
| 11 | + }, |
| 12 | + actions: { |
| 13 | + loadKeyNames: async function({ commit }) { |
| 14 | + const keyNames = await polykeyClient.listKeys() |
| 15 | + commit('loadKeyNames', keyNames) |
| 16 | + }, |
| 17 | + deleteKey: async function({ commit, state }, keyName) { |
| 18 | + const successful = await polykeyClient.deleteKey(keyName) |
| 19 | + if (successful) { |
| 20 | + const keyNames = await polykeyClient.listKeys() |
| 21 | + return commit('loadKeyNames', keyNames) |
| 22 | + } else { |
| 23 | + return commit('loadKeyNames', state.keyNames) |
| 24 | + } |
| 25 | + }, |
| 26 | + loadKeyPair: async function({ commit }) { |
| 27 | + const keyPair = await polykeyClient.getPrimaryKeyPair(true) |
| 28 | + commit('loadKeyPair', { publicKey: keyPair.public, privateKey: keyPair.private }) |
| 29 | + }, |
| 30 | + selectKey: async function({ commit }, keyName: string) { |
| 31 | + const keyContent = await polykeyClient.getKey(keyName) |
| 32 | + commit('selectKey', { selectedKeyName: keyName, selectedKeyContent: keyContent }) |
| 33 | + } |
| 34 | + }, |
| 35 | + mutations: { |
| 36 | + loadKeyNames: function(state, keyNames) { |
| 37 | + state.keyNames = keyNames |
| 38 | + }, |
| 39 | + loadKeyPair: function(state, { publicKey, privateKey }: { publicKey: string; privateKey: string }) { |
| 40 | + state.publicKey = publicKey |
| 41 | + state.privateKey = privateKey |
| 42 | + }, |
| 43 | + selectKey: function(state, { selectedKeyName, selectedKeyContent }) { |
| 44 | + state.selectedKeyName = selectedKeyName |
| 45 | + state.selectedKeyContent = selectedKeyContent |
| 46 | + } |
| 47 | + }, |
6 | 48 | getters: {} |
7 | 49 | } |
8 | 50 | // import { polykeyClient } from '@/store' |
|
0 commit comments