1
0

Hardware.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <main class="">
  3. <section class="max-w-5xl mx-auto">
  4. <div class="card-body">
  5. Connect your Ledger Nano S/X
  6. <button
  7. class="p-3 m-3 bg-pink-300 border-4 border-pink-500 rounded-xl"
  8. @click="connectLedger"
  9. >
  10. Connect Ledger
  11. </button>
  12. <div v-if="ledgerAddress" class="m-3 p-3">
  13. Ledger Address: {{ledgerAddress}}
  14. </div>
  15. </div>
  16. </section>
  17. </main>
  18. </template>
  19. <script>
  20. // FOR DEVELOPMENT PURPOSES ONLY
  21. // import '@ethersproject/shims'
  22. // import LedgerTransport from '@ledgerhq/hw-transport-webusb'
  23. // import LedgerBtc from '@ledgerhq/hw-app-btc'
  24. // import LedgerEth from '@ledgerhq/hw-app-eth'
  25. export default {
  26. data: () => {
  27. return {
  28. ledgerAddress: null,
  29. }
  30. },
  31. computed: {
  32. //
  33. },
  34. methods: {
  35. connectLedger() {
  36. const getBtcAddress = async () => {
  37. const transport = await LedgerTransport
  38. .create()
  39. .catch(err => console.error(err))
  40. const btc = new LedgerBtc(transport)
  41. /* Set puprose. */
  42. const purpose = 44
  43. /* Set coin type. */
  44. // const coinType = 0 // Legacy Bitcoin (BTC)
  45. const coinType = 145 // Bitcoin Cash (BCH)
  46. /* Set account. */
  47. const account = 0
  48. /* Set (has) change. */
  49. const change = 0
  50. /* Set (address) index. */
  51. const index = 0
  52. const result = await btc
  53. .getWalletPublicKey(`${purpose}'/${coinType}'/${account}'/${change}/${index}`)
  54. .catch(err => console.error(err))
  55. /* Return address. */
  56. return result.bitcoinAddress
  57. }
  58. const getEthAddress = async () => {
  59. const transport = await LedgerTransport
  60. .create()
  61. .catch(err => console.error(err))
  62. const eth = new LedgerEth(transport)
  63. /* Set puprose. */
  64. const purpose = 44
  65. /* Set coin type. */
  66. const coinType = 60 // Ethereum (BCH)
  67. /* Set account. */
  68. const account = 0
  69. /* Set (has) change. */
  70. const change = 0
  71. /* Set (address) index. */
  72. const index = 0
  73. const result = await eth
  74. .getWalletPublicKey(`${purpose}'/${coinType}'/${account}'/${change}/${index}`)
  75. .catch(err => console.error(err))
  76. /* Return address. */
  77. return result.bitcoinAddress
  78. }
  79. /* Request Bitcoin address. */
  80. getBtcAddress()
  81. .then(_address => {
  82. console.log('BITCOIN ADDRESS', _address)
  83. this.ledgerAddress = _address
  84. })
  85. /* Request Ethereum address. */
  86. getEthAddress()
  87. .then(_address => {
  88. console.log('ETHEREUM ADDRESS', _address)
  89. // this.ledgerAddress = _address
  90. })
  91. },
  92. },
  93. created: async function () {
  94. //
  95. },
  96. mounted: function () {
  97. //
  98. },
  99. }
  100. </script>