<commit_before>import MewConnect from '@myetherwallet/mewconnect-web-client'
import * as ethUtil from 'ethereumjs-util'
import EthereumjsTx from 'ethereumjs-tx'

export default class MewConnectWallet {
  constructor (options) {
    this.isHardwareWallet = true
    this.identifier = 'MEWconnect'
    this.brand = 'MEW'
    this.type = 'hardware'
    this.isHardwareWallet = true
    this.wallet = null

    options = options || {}

    this.id = 0
    this.hdk = null
    this.numWallets = 0

    this.defaultOptions = {
      path: 'm/44\'/60\'/0\'/0' // trezor default derivation path
    }
    const currentOptions = {
      ...this.defaultOptions,
      ...options
    }

    this.signalerUrl = currentOptions.signalerUrl || 'https://connect.mewapi.io'
    this.networkId = 1

    this.mewConnect = MewConnect.Client.init(null, null)

    this.getAccounts = this.getAccounts.bind(this)
    this.getMultipleAccounts = this.getMultipleAccounts.bind(this)
    this.signTransaction = this.signTransaction.bind(this)
    this.signMessage = this.signMessage.bind(this)

    this.mewConnect.on('RtcConnectedEvent', this.requestAddress.bind(this))
  }

  registerListener (event, listener) {
    this.mewConnect.on(event, listener)
  }

  requestAddress () {
    this.mewConnect.sendRtcMessage('address', '')
  }

  // ============== (Start) EthereumJs-wallet interface methods ======================
  getAddress () {
    if (this.wallet) {
      return this.wallet.address
    } else {
      return null
    }
  }

  getAddressString () {
    if (this.wallet) {
      return ethUtil.toChecksumAddress(this.getAddress())
    } else {
      return null
    }
  }

  // ============== (End) EthereumJs-wallet interface methods ======================

  // ============== (Start) Utility methods ======================
  get isHardware () {
    return this.isHardwareWallet
  }

  // Implementation required
  static async unlock () {
    return new MewConnectWallet()
  }

  // ============== (End) Required Utility methods ======================

  // ============== (Start) wallet usage methods ======================
  // Implementation required
  async getAccounts () {
    return this.wallet.address
  }

  // Implementation required (if only a single account exists, it should be returned)
  async getMultipleAccounts (count, offset) {
    return this.wallet.address
  }

  // Implementation required
  signMessage (msgData) {
    console.log('got data in mewConnectWallet', msgData) // todo remove dev item
    return new Promise((resolve, reject) => {
      try {
        let thisMessage = msgData.data ? msgData.data : msgData
        this.mewConnect.sendRtcMessage('signMessage', thisMessage)<commit_msg>investigate signMessage failure<commit_after>import MewConnect from '@myetherwallet/mewconnect-web-client'
import * as ethUtil from 'ethereumjs-util'
import EthereumjsTx from 'ethereumjs-tx'

export default class MewConnectWallet {
  constructor (options) {
    this.isHardwareWallet = true
    this.identifier = 'MEWconnect'
    this.brand = 'MEW'
    this.type = 'hardware'
    this.isHardwareWallet = true
    this.wallet = null

    options = options || {}

    this.id = 0
    this.hdk = null
    this.numWallets = 0

    this.defaultOptions = {
      path: 'm/44\'/60\'/0\'/0' // trezor default derivation path
    }
    const currentOptions = {
      ...this.defaultOptions,
      ...options
    }

    this.signalerUrl = currentOptions.signalerUrl || 'https://connect.mewapi.io'
    this.networkId = 1

    this.mewConnect = MewConnect.Client.init(null, null)

    this.getAccounts = this.getAccounts.bind(this)
    this.getMultipleAccounts = this.getMultipleAccounts.bind(this)
    this.signTransaction = this.signTransaction.bind(this)
    this.signMessage = this.signMessage.bind(this)

    this.mewConnect.on('RtcConnectedEvent', this.requestAddress.bind(this))
  }

  registerListener (event, listener) {
    this.mewConnect.on(event, listener)
  }

  requestAddress () {
    this.mewConnect.sendRtcMessage('address', '')
  }

  // ============== (Start) EthereumJs-wallet interface methods ======================
  getAddress () {
    if (this.wallet) {
      return this.wallet.address
    } else {
      return null
    }
  }

  getAddressString () {
    if (this.wallet) {
      return ethUtil.toChecksumAddress(this.getAddress())
    } else {
      return null
    }
  }

  // ============== (End) EthereumJs-wallet interface methods ======================

  // ============== (Start) Utility methods ======================
  get isHardware () {
    return this.isHardwareWallet
  }

  // Implementation required
  static async unlock () {
    return new MewConnectWallet()
  }

  // ============== (End) Required Utility methods ======================

  // ============== (Start) wallet usage methods ======================
  // Implementation required
  async getAccounts () {
    return this.wallet.address
  }

  // Implementation required (if only a single account exists, it should be returned)
  async getMultipleAccounts (count, offset) {
    return this.wallet.address
  }

  // todo: figure out why this isn't receiving the response from the app.  (check out the article about using wireshark to debug webrtc)
  signMessage (msgData) {
    console.log('got data in mewConnectWallet', msgData) // todo remove dev item
    return new Promise((resolve, reject) => {
      try {
        let thisMessage = msgData.data ? msgData.data : msgData
        this.mewConnect.sendRtcMessage('signMessage', thisMessage)
{'fraction_non_alphanumeric': 0.16576479076479075, 'fraction_numerical': 0.003246753246753247, 'mean_word_length': 3.242540168324407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6888793', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1619, 'n_words': 363}