How to use the @shapeshiftoss/hdwallet-core.makeEvent function in @shapeshiftoss/hdwallet-core

To help you get started, we’ve selected a few @shapeshiftoss/hdwallet-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shapeshift / hdwallet / packages / hdwallet-ledger-webusb / src / transport.ts View on Github external
public async call(coin: string, method: string, ...args: any[]): Promise {
    let response

    try {
      this.emit(`ledger.${coin}.${method}.call`, makeEvent({
        message_type: method,
        from_wallet: false,
        message: {}
      }))

      if (coin) {
        response = await new (translateCoin(coin))(this.transport)[method](...args)
      } else {
        // @ts-ignore
        response = await (translateMethod(method))(this.transport, ...args)
      }
    } catch (e) {
      console.error(e)
      return {
        success: false,
        payload: { error: e.toString() },
github shapeshift / hdwallet / packages / hdwallet-ledger / src / utils.ts View on Github external
if (result.payload.error.includes('0x6985')) {
      throw new core.ActionCancelled()
    }

    // Device is on the lock screen
    if (result.payload.error.includes('0x6f04')) {
      throw new core.DeviceLocked()
    }

    // Device disconnected during operation, typically due to app navigation
    if (result.payload.error.includes('DisconnectedDeviceDuringOperation')) {
      throw new core.DisconnectedDeviceDuringOperation()
    }

    if (transport) {
      transport.emit(`ledger.${result.coin}.${result.method}.call`, core.makeEvent({
        message_type: 'ERROR',
        from_wallet: true,
        message
      }))
    }

    throw new Error(`${message}: '${result.payload.error}'`)
  }
}
github shapeshift / hdwallet / packages / hdwallet-trezor-connect / src / transport.ts View on Github external
// Log TrezorConnect's event raw:
      this.emit(event.type, makeEvent({
        message_type: event.type,
        message: event,
        from_wallet: true
      }))

      // Then log it the 'unified' way:
      if (event.type === 'ui-request_pin') {
        this.emit(Events.PIN_REQUEST, makeEvent({
          message_type: Events.PIN_REQUEST,
          from_wallet: true
        }))
      } else if (event.type === 'ui-request_passphrase') {
        this.emit(Events.PASSPHRASE_REQUEST, makeEvent({
          message_type: Events.PASSPHRASE_REQUEST,
          from_wallet: true
        }))
      } else if (event.type === 'ui-request_confirmation') {
        if (event.payload.view == 'no-backup') {
          this.emit('NEEDS_BACKUP')
        }
      } else if (event.type === 'ui-button') {
        let kind = event.payload.code
        this.emit(Events.BUTTON_REQUEST, makeEvent({
          message_type: Events.BUTTON_REQUEST,
          from_wallet: true,
          message: kind
        }))
      }
    })
github shapeshift / hdwallet / packages / hdwallet-ledger-u2f / src / transport.ts View on Github external
public async call(coin: string, method: string, ...args: any[]): Promise {
    let response

    try {
      this.emit(`ledger.${coin}.${method}.call`, makeEvent({
        message_type: method,
        from_wallet: false,
        message: {}
      }))
      if (coin) {
        response = await new (translateCoin(coin))(this.transport)[method](...args)
      } else {
        response = await (translateMethod(method))(this.transport)
      }
    } catch (e) {
      console.error(e)
      return {
        success: false,
        payload: { error: e.toString() },
        coin,
        method,
github shapeshift / hdwallet / packages / hdwallet-trezor-connect / src / transport.ts View on Github external
public async call (method: string, msg: any, msTimeout?: number): Promise {
    this.emit(method, makeEvent({
      message_type: method,
      message: this.censor(method, msg),
      from_wallet: false
    }))

    let response = await TrezorConnectTransport.callQuiet(this.device, method, msg, msTimeout)

    this.emit(method, makeEvent({
      message_type: method,
      message: response,
      from_wallet: true
    }))

    return response
  }