tronHelper.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import API from '@/api'
  2. import { showError } from '@/util/util'
  3. import { Promise } from 'es6-promise'
  4. let TronHelper = {
  5. account: '',
  6. /**
  7. * @des 签名认证
  8. */
  9. async initTron () {
  10. if (!window.tronWeb) {
  11. showError('你还没有安装tron插件')
  12. return Promise.reject(new Error(''))
  13. }
  14. let account = window.tronWeb.defaultAddress.base58
  15. let randomRes = await API.user.getRandom2({ account: account })
  16. let s = window.tronWeb.sha3(randomRes.data.data.random)
  17. let resutlSign
  18. try {
  19. resutlSign = await window.tronWeb.trx.signMessage(s)
  20. } catch (e) {
  21. if (e == 'Invalid transaction provided') showError('请重新安装钱包插件')
  22. else showError(e)
  23. this.setLogining(false)
  24. return
  25. }
  26. // if (window.tronWeb.fullNode.host != 'https://api.trongrid.io') {
  27. // showError('tron不是主网')
  28. // return Promise.reject(new Error(''))
  29. // }
  30. try {
  31. // let rs = await window.tronWeb.trx.verifyMessage(s, resutlSign, account)
  32. return Promise.resolve({
  33. account: account,
  34. sign: resutlSign
  35. })
  36. } catch (e) {
  37. return Promise.reject(e)
  38. }
  39. }
  40. }
  41. export default TronHelper