store.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. export default new Vuex.Store({
  5. state: {
  6. contactsCards: [
  7. {
  8. name: "Alex",
  9. email: "alex@foo.bar",
  10. phone: "503-555-1212",
  11. fingerprint: "b1:92:b2:8e:f6:e2:ab:64:29:5b:20:d3:5c:c0:f4:35:b2:9d:6d:69:f6:8b:4c:fb:47:34:17:9b:b2:00:d0:06"
  12. },
  13. {
  14. name: "Billie",
  15. email: "billie@foo.bar",
  16. phone: "206-555-1212",
  17. fingerprint: "2f:d1:8f:ed:8f:a7:ca:e2:50:90:d9:e2:86:06:35:d2:81:cb:87:72:bb:2f:f3:44:5a:59:60:c0:c8:86:9d:7e"
  18. },
  19. {
  20. name: "Carol",
  21. email: "carol@foo.bar",
  22. phone: "971-555-1212",
  23. fingerprint: "7b:ae:11:ea:4b:83:a1:d0:56:62:73:dc:74:f0:14:6e:33:8a:3b:0b:53:85:b7:08:16:62:cf:b3:4f:56:d5:ed"
  24. },
  25. ],
  26. walletCards: [
  27. {
  28. name: "Drew",
  29. email: "drew@foo.bar",
  30. phone: "360-555-1212",
  31. fingerprint: "1f:42:61:c6:9f:5b:95:d7:56:c6:53:ca:26:ae:96:d9:08:d4:da:aa:61:7e:4e:83:45:af:ba:d1:a0:81:ec:41"
  32. },
  33. {
  34. name: "de2005",
  35. email: "de2005@foo.bar",
  36. phone: "",
  37. fingerprint: "d1:01:84:76:58:a7:cb:78:dc:bf:82:80:b0:cc:8a:ff:e2:64:60:5b:0f:00:1a:0c:7b:16:61:ab:14:b6:70:21"
  38. },
  39. {
  40. name: "Drew Jansbarn",
  41. email: "drew.jansbarn@foo.bar",
  42. phone: "800-555-1212",
  43. fingerprint: "e7:b8:37:31:d0:c6:b1:85:31:2d:08:e6:6f:7d:2d:b9:28:88:fa:60:5e:90:47:81:ba:26:bd:b4:91:d0:ed:03"
  44. },
  45. ],
  46. ssiKeystore: [
  47. {
  48. fingerprint: "1f:42:61:c6:9f:5b:95:d7:56:c6:53:ca:26:ae:96:d9:08:d4:da:aa:61:7e:4e:83:45:af:ba:d1:a0:81:ec:41",
  49. pubKey: "-----BEGIN PUBLIC KEY-----\nMFowDQYJKoZIhvcNAQEBBQADSQAwRgJBAM0PD8UbtbWvV1TNc1OxcN8F0630rnCf\nu7cFDcvFWxF8nizNmySM45iuxfL1UDhHIw+NK3W9XLf3tWAJsFog/vECAQM=\n-----END PUBLIC KEY-----\n",
  50. pvtKey: "-----BEGIN PRIVATE KEY-----\nMIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAzQ8PxRu1ta9XVM1z\nU7Fw3wXTrfSucJ+7twUNy8VbEXyeLM2bJIzjmK7F8vVQOEcjD40rdb1ct/e1YAmw\nWiD+8QIBAwJBAIi0tS4SeSPKOjiI940g9eoD4nP4dEsVJ89Ys90uPLZR4R/QiTHn\n7InvM94t8UUCiUS8GVDJ9cbL5YaHI+1OHisCIQD8/X1s71ox00W9NAmtYKWYLzAE\ndQ4MfU8K6IEm853xCQIhAM9/l2BqVs72gjrxprjwHbz5QwEHgF+QdtItvdOCjeCp\nAiEAqKj+SJ+RdozZKM1byOsZEB91WE4JXajfXJsAxKJpS1sCIQCKVQ+VnDnfTwF8\noRnQoBPTUNdWBQA/taSMHn6NAbPrGwIhAJiPFbMV0/fS0QnkCi5SbeutgQvt/5kl\n/ce8/2hn8Quh\n-----END PRIVATE KEY-----\n"
  51. },
  52. {
  53. fingerprint: "d1:01:84:76:58:a7:cb:78:dc:bf:82:80:b0:cc:8a:ff:e2:64:60:5b:0f:00:1a:0c:7b:16:61:ab:14:b6:70:21",
  54. pubKey: "-----BEGIN PUBLIC KEY-----\nMFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANvFBllgZ1c8RN3s7YGscjhrYOvFYM5t\nRvgiSIpJuP2d5PvW2YgdahZibfI6x+Z/bf2Fr0VtzNvQaX4Wz7fUEXkCAQM=\n-----END PUBLIC KEY-----\n",
  55. pvtKey: "-----BEGIN PRIVATE KEY-----\nMIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEA28UGWWBnVzxE3ezt\ngaxyOGtg68Vgzm1G+CJIikm4/Z3k+9bZiB1qFmJt8jrH5n9t/YWvRW3M29BpfhbP\nt9QReQIBAwJBAJKDWZDq7499gz6d86vITCWc60fY6zRI2frBhbGGe1O9XGOFJj4v\nYbsLl78gWqwd1LquxpvDIa08PBIvHXOvNEMCIQDu6+l7Nl72OjTfXY3ld+3+TWCk\n58vFwj3ocA4jnyPhSwIhAOt6paT0d2FDnCr1/FpsZLCYHuBz/VSVuCbywf/rKWHL\nAiEAn0fw/M7p+XwjP5Oz7k/z/t5Abe/dLoF+mvVewmoX64cCIQCc/G5t+E+WLRLH\nTqg8SEMgZWnq9/44Y9AZ9yv/8huWhwIhAMPfAlcKVSwzBlYsG12Z8LId9CYygAFC\n8J/a31IAbI61\n-----END PRIVATE KEY-----\n"
  56. },
  57. {
  58. fingerprint: "e7:b8:37:31:d0:c6:b1:85:31:2d:08:e6:6f:7d:2d:b9:28:88:fa:60:5e:90:47:81:ba:26:bd:b4:91:d0:ed:03",
  59. pubKey: "-----BEGIN PUBLIC KEY-----\nMFowDQYJKoZIhvcNAQEBBQADSQAwRgJBAMP598ybxxasAER0v8TXk2is+RY7D41g\nY5AttoJFtdBSaD2aRplzu2w+SaM3k/ePBDK8szzzUDAcprh7UV5uHwkCAQM=\n-----END PUBLIC KEY-----\n",
  60. pvtKey: "-----BEGIN PRIVATE KEY-----\nMIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAw/n3zJvHFqwARHS/\nxNeTaKz5FjsPjWBjkC22gkW10FJoPZpGmXO7bD5JozeT948EMryzPPNQMBymuHtR\nXm4fCQIBAwJBAIKmpTMShLnIAC2jKoM6YkXIpg7SCl5AQmAeeawueTWLGV3ZCgUi\npSYcRlz5pAivqOF1I20vKMWEMig/sWODuIsCIQD3aQ3GR/dakifzJ2buADVeW6+T\nZ21nZsdbZF843wxNRQIhAMrHxvFJyGkg6+zwWi/qUiiE3WqxvyuhDwAXvI5qHDz1\nAiEApPCz2YVPkbbFTMTvSVV46ZJ1DO+eRO8vkkLqJeoIM4MCIQCHL9n2MTBGFfKd\n9ZF1RuFwWJOcdn9ya19VZShe8WgoowIhANszYqJ3DPwIqHW2/umS4QRX+LmqnoUK\nZcUz254pkJas\n-----END PRIVATE KEY-----\n"
  61. },
  62. {
  63. fingerprint: "b1:92:b2:8e:f6:e2:ab:64:29:5b:20:d3:5c:c0:f4:35:b2:9d:6d:69:f6:8b:4c:fb:47:34:17:9b:b2:00:d0:06",
  64. pubKey: "-----BEGIN PUBLIC KEY-----\nMFowDQYJKoZIhvcNAQEBBQADSQAwRgJBAOjBnFap/cZB4lrIwLsy4gHozoTHHjtM\n3KM4i4vZiHZPxhs+TDLjlWDS/6+biwIZe5gu8tMNJtc5mfvWpQ/f6JsCAQM=\n-----END PUBLIC KEY-----\n"
  65. },
  66. {
  67. fingerprint: "2f:d1:8f:ed:8f:a7:ca:e2:50:90:d9:e2:86:06:35:d2:81:cb:87:72:bb:2f:f3:44:5a:59:60:c0:c8:86:9d:7e",
  68. pubKey: "-----BEGIN PUBLIC KEY-----\nMFowDQYJKoZIhvcNAQEBBQADSQAwRgJBALw/kW9IO9GBqwvTPHFYxCmKXpdvbGMP\nGYBZ0Gp8H9eP/H8yk3Ue+rbOYN7dXhDZey/GzomPbFrrsBA9H7o4VssCAQM=\n-----END PUBLIC KEY-----\n"
  69. },
  70. {
  71. fingerprint: "7b:ae:11:ea:4b:83:a1:d0:56:62:73:dc:74:f0:14:6e:33:8a:3b:0b:53:85:b7:08:16:62:cf:b3:4f:56:d5:ed",
  72. pubKey: "-----BEGIN PUBLIC KEY-----\nMFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANa3oWtCWZncg4OaXbvwMmm0g+q97b2r\niN8aoAurHtxN6+AkvnySWGlLqpRrEnTETohDJfHJfGCRcH+drdvja48CAQM=\n-----END PUBLIC KEY-----\n"
  73. },
  74. ],
  75. },
  76. getters: {
  77. numContactsCards: state => state.contactsCards ? state.contactsCards.length : 0,
  78. numKeys: state => state.ssiKeystore ? state.ssiKeystore.length : 0,
  79. numWalletCards: state => state.walletCards ? state.walletCards.length : 0,
  80. getCardFromFingerprint: state => fingerprint =>
  81. state.contactsCards
  82. ? state.contactsCards.filter(x => x.fingerprint === fingerprint)
  83. : [],
  84. getKeyFromFingerprint: state => fingerprint =>
  85. state.ssiKeystore
  86. ? state.ssiKeystore.filter(x => x.fingerprint === fingerprint)
  87. : [],
  88. getState: state => state,
  89. },
  90. mutations: {
  91. replaceStateFromBlob(state, blob) {
  92. try {
  93. //TODO: validate the json schema
  94. //console.log(blob)
  95. const notablob = JSON.parse(blob)
  96. if (notablob) {
  97. this.replaceState(notablob)
  98. }
  99. } catch (exception){
  100. console.error(exception)
  101. }
  102. },
  103. addContactsCardFromBlob({ contactsCards }, blob) {
  104. const card = JSON.parse(blob)
  105. if (this.state === undefined) {
  106. this.replaceState({
  107. walletCards:[],
  108. contactsCards:[ card ],
  109. ssiKeystore:[],
  110. })
  111. } else if (contactsCards === undefined) {
  112. this.replaceState({
  113. walletCards: this.state.walletCards,
  114. contactsCards: [ card ],
  115. ssiKeystore: this.state.ssiKeystore,
  116. })
  117. } else {
  118. contactsCards.push(card)
  119. }
  120. },
  121. addContactsCard({ contactsCards }, card) {
  122. if (this.state === undefined) {
  123. this.replaceState({
  124. walletCards:[],
  125. contactsCards:[ card ],
  126. ssiKeystore:[],
  127. })
  128. } else if (contactsCards === undefined) {
  129. this.replaceState({
  130. walletCards: this.state.walletCards,
  131. contactsCards: [ card ],
  132. ssiKeystore: this.state.ssiKeystore,
  133. })
  134. } else {
  135. contactsCards.push(card)
  136. }
  137. },
  138. rmContactsCard({ contactsCards }, index) {
  139. if (this.state === undefined) {
  140. this.replaceState({
  141. walletCards:[],
  142. contactsCards:[],
  143. ssiKeystore:[],
  144. })
  145. } else if (contactsCards === undefined) {
  146. this.replaceState({
  147. walletCards: this.state.walletCards,
  148. contactsCards: [],
  149. ssiKeystore: this.state.ssiKeystore,
  150. })
  151. } else {
  152. contactsCards.splice(index, 1)
  153. }
  154. },
  155. addWalletCard({ walletCards }, card) {
  156. if (this.state === undefined) {
  157. this.replaceState({
  158. walletCards:[ card ],
  159. contactsCards:[],
  160. ssiKeystore:[],
  161. })
  162. } else if (walletCards === undefined) {
  163. this.replaceState({
  164. walletCards:[ card ],
  165. contactsCards: this.state.contactsCards,
  166. ssiKeystore: this.state.ssiKeystore,
  167. })
  168. } else {
  169. walletCards.push(card)
  170. }
  171. },
  172. rmWalletCard({ walletCards }, index) {
  173. if (this.state === undefined) {
  174. this.replaceState({
  175. walletCards:[],
  176. contactsCards:[],
  177. ssiKeystore:[],
  178. })
  179. } else if (walletCards === undefined) {
  180. this.replaceState({
  181. walletCards:[],
  182. contactsCards: this.state.contactsCards,
  183. ssiKeystore: this.state.ssiKeystore,
  184. })
  185. } else {
  186. walletCards.splice(index, 1)
  187. }
  188. },
  189. createKeypair({ ssiKeystore }, instance) {
  190. if (this.state === undefined) {
  191. this.replaceState({
  192. walletCards: [],
  193. contactsCards: [],
  194. ssiKeystore: [instance],
  195. })
  196. } else if (ssiKeystore === undefined) {
  197. this.replaceState({
  198. walletCards: this.state.walletCards,
  199. contactsCards: this.state.contactsCards,
  200. ssiKeystore: [instance],
  201. })
  202. } else {
  203. ssiKeystore.push(instance)
  204. }
  205. },
  206. },
  207. actions: {
  208. addKeypair: function(context, instance) {
  209. context.commit("createKeypair", instance)
  210. },
  211. addContact(context, instance) {
  212. context.commit("addContactsCard", instance)
  213. },
  214. rmCard(context, index) {
  215. context.commit("rmContactsCard", index)
  216. },
  217. rmCred(context, index) {
  218. context.commit("rmWalletCard", index)
  219. }
  220. }
  221. })