Ring.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div>
  3. <h1>Key Ring</h1>
  4. <p>{{ numKeys }}</p>
  5. <div v-if="numKeys > 0">
  6. <ul>
  7. <li v-for="(key, index) in ssiKeystore" v-bind:key="index">
  8. <span>{{ key.fingerprint }}</span>&nbsp;&#45;
  9. <span v-if="key.pubKey && key.pubKey !== ''">********</span>
  10. <span v-else>NO_PUB</span>&nbsp;&#45;
  11. <span v-if="key.pvtKey && key.pvtKey !== ''">********</span>
  12. <span v-else>NO_PRIVATE</span>
  13. </li>
  14. </ul>
  15. </div>
  16. <div v-if="false">
  17. <hr />
  18. <h2>Create New Key Pair</h2>
  19. <p><strong>ATTENTION&#58;</strong>
  20. This will create a new key pair.</p>
  21. <button v-on:click="createKeypair()" class="danger">Create Key Pair</button>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import {mapState, mapGetters, mapActions} from "vuex"
  27. export default {
  28. name: "Ring",
  29. data() {
  30. return {}
  31. },
  32. computed: {
  33. ...mapState([
  34. "ssiKeystore"
  35. ]),
  36. ...mapGetters([
  37. "numKeys"
  38. ])
  39. },
  40. methods: {
  41. ...mapActions({
  42. addKeypair: "addKeypair",
  43. }),
  44. createKeypair: function() {
  45. //NOTE: Using a low prime 60 for performace during development!
  46. //NOTE: Using DH instead of RSA for now.
  47. //TODO: Change this to a higher number or use a key generation
  48. // local service to offload to task.
  49. // 4096 takes forever on my system.
  50. const crypto = require('crypto');
  51. const dh = crypto.createDiffieHellman(64);
  52. dh.generateKeys();
  53. let keyPair = {
  54. fingerprint: this.getHash(dh.getPublicKey('hex'), "sha1", "hex")
  55. , pubKey: dh.getPublicKey('hex')
  56. , pvtKey: dh.getPrivateKey('hex')}
  57. console.info(keyPair)
  58. this.addKeypair(keyPair)
  59. },
  60. // getFingerprint: function(protoFingerprint) {
  61. // //NOTE: Right now the creation only makes the sha1, not the last octet
  62. // //https://tools.ietf.org/html/rfc4880#section-12.2
  63. // //TODO: Take a look at this:
  64. // //https://github.com/gnewpg/node-pgp/pull/7/commits/ace46fa5702d2cc81726608c39036667bd9a1ff1
  65. // },
  66. getHash: function(text, hType, rType) {
  67. try {
  68. const crypto = require('crypto');
  69. const hash = crypto.createHash(hType)
  70. .update(text)
  71. .digest(rType);
  72. return hash.toUpperCase();
  73. } catch (err) {
  74. console.error('failed to create hash');
  75. }
  76. },
  77. }
  78. }
  79. </script>