Cred.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div>
  3. <h1>Cred from IDs</h1>
  4. <div v-if="fingerprint">
  5. <p>{{fingerprint}}</p>
  6. <div v-for="(card, index) in walletCards" v-bind:key="index">
  7. <div v-if="card.fingerprint.replace(/[: ]/gi,'') === fingerprint.replace(/[: ]/gi,'')">
  8. <BusinessCard :card="card"/>
  9. <TextCrypto :rsaPvtKey="getPvtKey(fingerprint)"/>
  10. <TextEncrypter :rsaPubKey="getPubKey(fingerprint)"/>
  11. <TextDecrypter :rsaPvtKey="getPvtKey(fingerprint)"/>
  12. <p>
  13. <pre>{{JSON.stringify(card, null, 1)}}</pre>
  14. </p>
  15. <p><button v-on:click="addAsContact(card)">Add to Contacts</button></p>
  16. <p><button v-on:click="toggleLock()">Click to toggle lock</button></p>
  17. <div v-if="!locked">
  18. <p><strong>WARNING&#58;</strong>
  19. This will remove the card if you click the button below.</p>
  20. <button v-on:click="rmCred(index)" class="danger">Remove Card</button>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. <div v-else>
  26. <p>No fingerprint.</p>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import {mapState, mapGetters, mapMutations, mapActions} from "vuex"
  32. import BusinessCard from '@/components/BusinessCard.vue'
  33. import TextCrypto from '@/components/TextCrypto.vue'
  34. import TextDecrypter from '@/components/TextDecrypter.vue'
  35. import TextEncrypter from '@/components/TextEncrypter.vue'
  36. export default {
  37. name: "Card",
  38. components: {
  39. BusinessCard,
  40. TextCrypto,
  41. TextDecrypter,
  42. TextEncrypter
  43. },
  44. data() {
  45. return {
  46. locked: true
  47. }
  48. },
  49. props: ["fingerprint"],
  50. computed: {
  51. ...mapState([
  52. "walletCards",
  53. ])
  54. },
  55. methods: {
  56. ...mapGetters({
  57. keyPair: "getKeyFromFingerprint"
  58. }),
  59. ...mapMutations([
  60. "addWalletCard",
  61. "rmWalletCard",
  62. ]),
  63. ...mapActions({
  64. addAsContact: "addContact",
  65. }),
  66. ...mapActions({
  67. rmCred: "rmCred",
  68. }),
  69. getPubKey: function(fingerprint) {
  70. const keyPairs = this.keyPair()(fingerprint)
  71. return (keyPairs.length > 0) ? keyPairs[0].pubKey : undefined
  72. },
  73. getPvtKey: function(fingerprint) {
  74. const keyPairs = this.keyPair()(fingerprint)
  75. return (keyPairs.length > 0) ? keyPairs[0].pvtKey : undefined
  76. },
  77. toggleLock: function() {
  78. this.locked = !this.locked
  79. },
  80. getAvatar: function(email) {
  81. let hexval = this.getHash(email);
  82. return `https://www.libravatar.org/avatar/${hexval}?s=80`;
  83. },
  84. getHash: function(text) {
  85. try {
  86. const crypto = require('crypto');
  87. const hash = crypto.createHash('sha256')
  88. .update(text)
  89. .digest('hex');
  90. return hash;
  91. } catch (err) {
  92. console.log('crypto support is disabled!');
  93. }
  94. }
  95. }
  96. }
  97. </script>
  98. <style scoped>
  99. </style>