{"version":3,"file":"iota.cjs","sources":["../src/guards.js","../src/iota.js","../src/error.js"],"sourcesContent":["import Joi from 'joi';\n\nconst validInteger = Joi.number().integer();\nconst validSecurity = validInteger.min(1).max(3); // low, medium or high\nconst validIndex = validInteger.min(0).max(4294967295); // 32 bit unsigned int\nconst validValue = validInteger.min(0).max(2779530283277761);\nconst validBalance = validInteger.min(1).max(2779530283277761);\n\nconst validTrytes = Joi.string().regex(/^[A-Z9]+$/); // tryte string in the default base-27 encoding\nconst validTag = validTrytes.allow('').max(27);\nconst validAddress = Joi.alternatives().try(\n  validTrytes.length(81), // without checksum\n  validTrytes.length(90) // with checksum\n);\n\nconst validTransfers = Joi.array()\n  .items(\n    Joi.object({\n      address: validAddress.required(),\n      tag: validTag.required(),\n      value: validValue.required(),\n    }).unknown()\n  )\n  .min(1);\nconst validInputs = Joi.array()\n  .items(\n    Joi.object({\n      address: validAddress.required(),\n      balance: validBalance.required(),\n      keyIndex: validIndex.required(),\n      tags: Joi.array().items(validTag).optional(),\n    }).unknown()\n  )\n  .min(1);\nconst validRemainder = Joi.object({\n  address: validAddress.required(),\n  keyIndex: validIndex.required(),\n  tag: validTag.optional(),\n}).unknown();\n\nexport function string(value) {\n  Joi.assert(value, Joi.string().required());\n}\n\nexport function security(value) {\n  Joi.assert(value, validSecurity.required());\n}\n\nexport function index(value) {\n  Joi.assert(value, validIndex.required());\n}\n\nexport function transfers(value) {\n  Joi.assert(value, validTransfers.required());\n}\n\nexport function inputs(value) {\n  Joi.assert(value, validInputs.required());\n}\n\nexport function remainder(value) {\n  Joi.assert(value, validRemainder.optional());\n}\n\nexport function trytes(value) {\n  Joi.assert(value, validTrytes.required());\n}\n\nexport function nullaryFunc(value) {\n  Joi.assert(value, Joi.func().arity(0).required());\n}\n","import Struct from 'struct';\nimport Bundle from 'iota.lib.js/lib/crypto/bundle/bundle.js';\nimport {\n  addChecksum,\n  noChecksum,\n  transactionTrytes,\n} from 'iota.lib.js/lib/utils/utils.js';\nimport bippath from 'bip32-path';\nimport semver from 'semver';\nimport { getErrorMessage } from './error';\nimport * as guards from './guards';\n\n/**\n * IOTA API\n * @module hw-app-iota\n */\n\nconst CLA = 0x7a;\nconst Commands = {\n  // specific timeouts:\n  INS_SET_SEED: 0x01, // TIMEOUT_CMD_NON_USER_INTERACTION\n  INS_PUBKEY: 0x02, // TIMEOUT_CMD_PUBKEY\n  INS_TX: 0x03, // TIMEOUT_CMD_NON_USER_INTERACTION => TIMEOUT_CMD_USER_INTERACTION (IF cur_idx == lst_idx)\n  INS_SIGN: 0x04, // TIMEOUT_CMD_PUBKEY\n  INS_GET_APP_CONFIG: 0x10, // TIMEOUT_CMD_NON_USER_INTERACTION\n  INS_RESET: 0xff, // TIMEOUT_CMD_NON_USER_INTERACTION\n};\nconst TIMEOUT_CMD_PUBKEY = 10000;\nconst TIMEOUT_CMD_NON_USER_INTERACTION = 10000;\nconst TIMEOUT_CMD_USER_INTERACTION = 150000;\n\nconst LEGACY_VERSION_RANGE = '<0.5';\nconst DEFAULT_SECURITY = 2;\nconst HASH_LENGTH = 81;\nconst TAG_LENGTH = 27;\nconst SIGNATURE_FRAGMENT_SLICE_LENGTH = 3 * HASH_LENGTH;\nconst EMPTY_TAG = '9'.repeat(TAG_LENGTH);\n\n/**\n * Class for the interaction with the Ledger IOTA application.\n *\n * @example\n * import Iota from \"hw-app-iota\";\n * const iota = new Iota(transport);\n */\nclass Iota {\n  constructor(transport) {\n    transport.decorateAppAPIMethods(\n      this,\n      [\n        'setActiveSeed',\n        'getAddress',\n        'prepareTransfers',\n        'getAppVersion',\n        'getAppMaxBundleSize',\n      ],\n      'IOT'\n    );\n\n    this.transport = transport;\n    this.config = undefined;\n    this.security = 0;\n    this.pathArray = undefined;\n  }\n\n  /**\n   * Prepares the IOTA seed to be used for subsequent calls.\n   *\n   * @param {String} path - String representation of the BIP32 path. At most 5 levels.\n   * @param {Integer} [security=2] - IOTA security level to use\n   * @example\n   * iota.setActiveSeed(\"44'/4218'/0'/0'\", 2);\n   **/\n  async setActiveSeed(path, security = DEFAULT_SECURITY) {\n    guards.string(path);\n    guards.security(security);\n\n    this.pathArray = Iota._validatePath(path);\n    this.security = security;\n\n    // query the app config, if not present\n    this.config = this.config ? this.config : await this._getAppConfig();\n\n    if (semver.satisfies(this.config.app_version, LEGACY_VERSION_RANGE)) {\n      // use legacy structs\n      this._createPubkeyInput = this._createPubkeyInputLegacy;\n      this._createTxInput = this._createTxInputLegacy;\n\n      await this._setSeed();\n    } else {\n      // reset the state on the Ledger\n      await this._reset(true);\n    }\n  }\n\n  /**\n   * Generates an address index-based.\n   * The result depends on the initalized seed and security level.\n   *\n   * @param {Integer} index - Index of the address\n   * @param {Object} [options]\n   * @param {Boolean} [options.checksum=false] - Append 9 tryte checksum\n   * @param {Boolean} [options.display=false] - Display generated address on display\n   * @returns {Promise<String>} Tryte-encoded address\n   * @example\n   * iota.getAddress(0, { checksum: true });\n   **/\n  async getAddress(index, options = {}) {\n    this._assertInitialized();\n    guards.index(index);\n\n    const checksum = options.checksum || false;\n    const display = options.display || false;\n\n    const address = await this._publicKey(index, display);\n    if (checksum) {\n      return addChecksum(address);\n    }\n    return address;\n  }\n\n  /**\n   * Prepares the array of raw transaction data (trytes) by generating a bundle and signing the inputs.\n   *\n   * @param {Object[]} transfers - Transfer objects\n   * @param {String} transfers[].address - Tryte-encoded address of recipient, with or without the 9 tryte checksum\n   * @param {Integer} transfers[].value - Value to be transferred\n   * @param {String} transfers[].tag - Tryte-encoded tag. Maximum value is 27 trytes.\n   * @param {Object[]} inputs - Inputs used for funding the transfer\n   * @param {String} inputs[].address - Tryte-encoded source address, with or without the 9 tryte checksum\n   * @param {Integer} inputs[].balance - Balance of that input\n   * @param {String} inputs[].keyIndex - Index of the address\n   * @param {String[]} [inputs[].tags] - Tryte-encoded tags, one for each security level.\n   * @param {Object} [remainder] - Destination for sending the remainder value (of the inputs) to.\n   * @param {String} remainder.address - Tryte-encoded address, with or without the 9 tryte checksum\n   * @param {Integer} remainder.keyIndex - Index of the address\n   * @param {String} [remainder.tag] - Tryte-encoded tag. Maximum value is 27 trytes.\n   * @param {Function} [now = Date.now()] - Function to get the milliseconds since the UNIX epoch for timestamps.\n   * @returns {Promise<String[]>} Transaction trytes of 2673 trytes per transaction\n   */\n  async prepareTransfers(transfers, inputs, remainder, now = () => Date.now()) {\n    this._assertInitialized();\n    guards.transfers(transfers);\n    guards.inputs(inputs);\n    guards.remainder(remainder);\n    guards.nullaryFunc(now);\n\n    if (transfers.length != 1) {\n      throw new Error('unsupported number of transfers');\n    }\n\n    remainder = Iota._validateRemainder(transfers, inputs, remainder);\n    const trytes = await this._prepareTransfers(\n      transfers,\n      inputs,\n      remainder,\n      now\n    );\n    // reset the bundle\n    await this._reset(true);\n\n    return trytes;\n  }\n\n  /**\n   * Retrieves version information about the installed application from the device.\n   *\n   * @returns {Promise<String>} Semantic Version string (i.e. MAJOR.MINOR.PATCH)\n   **/\n  async getAppVersion() {\n    const config = await this._getAppConfig();\n    // update the stored config\n    this.config = config;\n\n    return config.app_version;\n  }\n\n  /**\n   * Retrieves the largest supported number of transactions (including meta transactions)\n   * in one transfer bundle from the device.\n   *\n   * @returns {Promise<Integer>} Maximum bundle size\n   **/\n  async getAppMaxBundleSize() {\n    const config = await this._getAppConfig();\n    // update the stored config\n    this.config = config;\n\n    // return value from config or default 8\n    return config.app_max_bundle_size ? config.app_max_bundle_size : 8;\n  }\n\n  ///////// Private methods should not be called directly! /////////\n\n  static _validatePath(path) {\n    let pathArray;\n    try {\n      pathArray = bippath.fromString(path).toPathArray();\n    } catch (e) {\n      throw new Error('\"path\" invalid: ' + e.message);\n    }\n\n    if (!pathArray || pathArray.length < 2 || pathArray.length > 5) {\n      throw new Error('\"path\" invalid: ' + 'Invalid path length');\n    }\n\n    return pathArray;\n  }\n\n  _assertInitialized() {\n    if (!this.security) {\n      throw new Error('seed not yet initialized');\n    }\n  }\n\n  _addSeedFields(struct) {\n    return struct\n      .word8('security')\n      .word32Ule('pathLength')\n      .array('pathArray', this.pathArray.length, 'word32Ule');\n  }\n\n  _initSeedFields(struct) {\n    const fields = struct.fields;\n    fields.security = this.security;\n    fields.pathLength = this.pathArray.length;\n    fields.pathArray = this.pathArray;\n  }\n\n  async _setSeed() {\n    const setSeedInStruct = new Struct();\n    this._addSeedFields(setSeedInStruct);\n\n    setSeedInStruct.allocate();\n    this._initSeedFields(setSeedInStruct);\n\n    await this._sendCommand(\n      Commands.INS_SET_SEED,\n      0,\n      0,\n      setSeedInStruct.buffer(),\n      TIMEOUT_CMD_NON_USER_INTERACTION\n    );\n  }\n\n  _createPubkeyInputLegacy(index) {\n    let struct = new Struct();\n    struct = struct.word32Ule('index');\n\n    struct.allocate();\n\n    struct.fields.index = index;\n\n    return struct;\n  }\n\n  _createPubkeyInput(index) {\n    let struct = new Struct();\n    this._addSeedFields(struct);\n    struct = struct.word32Ule('index');\n\n    struct.allocate();\n\n    this._initSeedFields(struct);\n    struct.fields.index = index;\n\n    return struct;\n  }\n\n  async _publicKey(index, display) {\n    const pubkeyInStruct = this._createPubkeyInput(index);\n\n    const response = await this._sendCommand(\n      Commands.INS_PUBKEY,\n      display ? 0x01 : 0x00,\n      0,\n      pubkeyInStruct.buffer(),\n      TIMEOUT_CMD_PUBKEY\n    );\n\n    const pubkeyOutStruct = new Struct().chars('address', HASH_LENGTH);\n    pubkeyOutStruct.setBuffer(response);\n\n    return pubkeyOutStruct.fields.address;\n  }\n\n  static _validateRemainder(transfers, inputs, remainder) {\n    const balance = inputs.reduce((a, i) => a + i.balance, 0);\n    const payment = transfers.reduce((a, t) => a + t.value, 0);\n\n    if (balance < payment) {\n      throw new Error('insufficient balance');\n    } else if (balance > payment) {\n      if (!remainder) {\n        throw new Error('\"remainder\" is required');\n      }\n      return {\n        address: remainder.address,\n        value: balance - payment,\n        keyIndex: remainder.keyIndex,\n      };\n    }\n\n    // ignore the remainder, if there is no change\n    return undefined;\n  }\n\n  async _sign(index, sliceLength) {\n    const signInStruct = new Struct().word32Ule('index');\n\n    signInStruct.allocate();\n    signInStruct.fields.index = index;\n\n    const response = await this._sendCommand(\n      Commands.INS_SIGN,\n      0,\n      0,\n      signInStruct.buffer(),\n      TIMEOUT_CMD_PUBKEY\n    );\n\n    const signOutStruct = new Struct()\n      .chars('signature', sliceLength)\n      .word8Sle('fragmentsRemaining');\n    signOutStruct.setBuffer(response);\n\n    return {\n      signature: signOutStruct.fields.signature,\n      fragmentsRemaining: signOutStruct.fields.fragmentsRemaining,\n    };\n  }\n\n  _createTxInputLegacy(address, address_idx, value, tag, tx_idx, tx_len, time) {\n    let struct = new Struct();\n    struct = struct\n      .chars('address', HASH_LENGTH)\n      .word32Ule('address_idx')\n      .word64Sle('value')\n      .chars('tag', TAG_LENGTH)\n      .word32Ule('tx_idx')\n      .word32Ule('tx_len')\n      .word32Ule('time');\n\n    struct.allocate();\n\n    const fields = struct.fields;\n    fields.address = address;\n    fields.address_idx = address_idx;\n    fields.value = value;\n    fields.tag = tag;\n    fields.tx_idx = tx_idx;\n    fields.tx_len = tx_len;\n    fields.time = time;\n\n    return struct;\n  }\n\n  _createTxInput(address, address_idx, value, tag, tx_idx, tx_len, time) {\n    let struct = new Struct();\n    if (tx_idx == 0) {\n      this._addSeedFields(struct);\n    }\n    struct = struct\n      .chars('address', HASH_LENGTH)\n      .word32Ule('address_idx')\n      .word64Sle('value')\n      .chars('tag', TAG_LENGTH)\n      .word32Ule('tx_idx')\n      .word32Ule('tx_len')\n      .word32Ule('time');\n\n    struct.allocate();\n\n    if (tx_idx == 0) {\n      this._initSeedFields(struct);\n    }\n    const fields = struct.fields;\n    fields.address = address;\n    fields.address_idx = address_idx;\n    fields.value = value;\n    fields.tag = tag;\n    fields.tx_idx = tx_idx;\n    fields.tx_len = tx_len;\n    fields.time = time;\n\n    return struct;\n  }\n\n  async _transaction(address, address_idx, value, tag, tx_idx, tx_len, time) {\n    const txInStruct = this._createTxInput(\n      address,\n      address_idx,\n      value,\n      tag,\n      tx_idx,\n      tx_len,\n      time\n    );\n\n    let timeout = TIMEOUT_CMD_NON_USER_INTERACTION;\n    if (tx_idx == tx_len) {\n      timeout = TIMEOUT_CMD_USER_INTERACTION;\n    }\n\n    const response = await this._sendCommand(\n      Commands.INS_TX,\n      tx_idx == 0 ? 0x00 : 0x80,\n      0,\n      txInStruct.buffer(),\n      timeout\n    );\n\n    const txOutStruct = new Struct()\n      .word8('finalized')\n      .chars('bundleHash', HASH_LENGTH);\n    txOutStruct.setBuffer(response);\n\n    return {\n      finalized: txOutStruct.fields.finalized,\n      bundleHash: txOutStruct.fields.bundleHash,\n    };\n  }\n\n  async _getSignatureFragments(index, sliceLength) {\n    const numSlices = (this.security * 2187) / sliceLength;\n\n    let signature = '';\n    for (let i = 1; i <= numSlices; i++) {\n      const result = await this._sign(index, sliceLength);\n      signature += result.signature;\n\n      // the remaining fragments must match the num slices\n      if ((i === numSlices) != (result.fragmentsRemaining === 0)) {\n        throw new Error('wrong signture length');\n      }\n    }\n\n    // split into segments of exactly 2187 chars\n    return signature.match(/.{2187}/g);\n  }\n\n  async _addSignatureFragmentsToBundle(bundle) {\n    for (let i = 0; i < bundle.bundle.length; i++) {\n      const tx = bundle.bundle[i];\n\n      // only sign inputs\n      if (tx.value >= 0) {\n        continue;\n      }\n\n      // compute all the signature fragments for that input transaction\n      const signatureFragments = await this._getSignatureFragments(\n        i,\n        SIGNATURE_FRAGMENT_SLICE_LENGTH\n      );\n      // and set the first fragment\n      tx.signatureMessageFragment = signatureFragments.shift();\n\n      // set the signature fragments for all successive meta transactions\n      const address = tx.address;\n      for (let j = 1; j < this.security; j++) {\n        if (++i >= bundle.bundle.length) {\n          return;\n        }\n\n        const tx = bundle.bundle[i];\n        if (tx.address === address && tx.value === 0) {\n          tx.signatureMessageFragment = signatureFragments.shift();\n        }\n      }\n    }\n  }\n\n  async _signBundle(bundle, addressKeyIndices) {\n    let finalized = false;\n    let bundleHash = '';\n    for (const tx of bundle.bundle) {\n      const keyIndex = addressKeyIndices[tx.address]\n        ? addressKeyIndices[tx.address]\n        : 0;\n      const result = await this._transaction(\n        tx.address,\n        keyIndex,\n        tx.value,\n        tx.obsoleteTag,\n        tx.currentIndex,\n        tx.lastIndex,\n        tx.timestamp\n      );\n      finalized = result.finalized;\n      bundleHash = result.bundleHash;\n    }\n\n    if (!finalized) {\n      throw new Error('bundle not finalized');\n    }\n    if (bundleHash !== bundle.bundle[0].bundle) {\n      throw new Error('wrong bundle hash');\n    }\n\n    await this._addSignatureFragmentsToBundle(bundle);\n  }\n\n  _hasDuplicateAddresses(transfers, inputs, remainder) {\n    const set = new Set();\n    transfers.forEach((t) => set.add(t.address));\n    inputs.forEach((i) => set.add(i.address));\n    if (remainder && set.has(remainder.address)) {\n      return true;\n    }\n\n    return set.length === transfers.length + inputs.length;\n  }\n\n  async _prepareTransfers(transfers, inputs, remainder, now) {\n    transfers = transfers.map((t) => ({\n      ...t,\n      // remove checksum\n      address: noChecksum(t.address),\n      // pad tag\n      tag: t.tag ? t.tag.padEnd(TAG_LENGTH, '9') : EMPTY_TAG,\n    }));\n    inputs = inputs.map((i) => ({\n      ...i,\n      // remove checksum\n      address: noChecksum(i.address),\n      // pad tags\n      tags: i.tags ? i.tags.map((tag) => tag.padEnd(TAG_LENGTH, '9')) : null,\n    }));\n    if (remainder) {\n      // remove checksum\n      remainder = {\n        ...remainder,\n        // remove checksum\n        address: noChecksum(remainder.address),\n        // pad tag\n        tag: remainder.tag ? remainder.tag.padEnd(TAG_LENGTH, '9') : EMPTY_TAG,\n      };\n    }\n\n    if (this._hasDuplicateAddresses(transfers, inputs, remainder)) {\n      throw new Error('transaction must not contain duplicate addresses');\n    }\n\n    // use the current time\n    const timestamp = Math.floor(now() / 1000);\n    let bundle = new Bundle();\n\n    transfers.forEach((x) =>\n      bundle.addEntry(1, x.address, x.value, x.tag, timestamp, -1)\n    );\n    inputs.forEach((x) => {\n      for (let i = 0; i < this.security; i++) {\n        bundle.addEntry(\n          1,\n          x.address,\n          i == 0 ? -x.balance : 0,\n          x.tags ? x.tags[i] : EMPTY_TAG,\n          timestamp,\n          x.keyIndex\n        );\n      }\n    });\n    if (remainder) {\n      bundle.addEntry(\n        1,\n        remainder.address,\n        remainder.value,\n        remainder.tag,\n        timestamp,\n        remainder.keyIndex\n      );\n    }\n    bundle.addTrytes([]);\n    bundle.finalize();\n\n    // map internal addresses to their index\n    const addressKeyIndices = {};\n    inputs.forEach((i) => (addressKeyIndices[i.address] = i.keyIndex));\n    if (remainder) {\n      addressKeyIndices[remainder.address] = remainder.keyIndex;\n    }\n\n    // sign the bundle on the ledger\n    await this._signBundle(bundle, addressKeyIndices);\n\n    // compute and return the corresponding trytes\n    const bundleTrytes = [];\n    bundle.bundle.forEach((tx) => bundleTrytes.push(transactionTrytes(tx)));\n    return bundleTrytes.reverse();\n  }\n\n  _createAppConfigOutputLegacy() {\n    const struct = new Struct()\n      .word8('app_flags')\n      .word8('app_version_major')\n      .word8('app_version_minor')\n      .word8('app_version_patch');\n\n    return struct;\n  }\n\n  _createAppConfigOutput() {\n    const struct = new Struct()\n      .word8('app_version_major')\n      .word8('app_version_minor')\n      .word8('app_version_patch')\n      .word8('app_max_bundle_size')\n      .word8('app_flags');\n\n    return struct;\n  }\n\n  async _getAppConfig() {\n    const response = await this._sendCommand(\n      Commands.INS_GET_APP_CONFIG,\n      0,\n      0,\n      undefined,\n      TIMEOUT_CMD_NON_USER_INTERACTION\n    );\n\n    let getAppConfigOutStruct = this._createAppConfigOutput();\n    // check whether the response matches the struct plus 2 bytes status code\n    if (response.length < getAppConfigOutStruct.length() + 2) {\n      getAppConfigOutStruct = this._createAppConfigOutputLegacy();\n    }\n    getAppConfigOutStruct.setBuffer(response);\n\n    const fields = getAppConfigOutStruct.fields;\n    return {\n      app_max_bundle_size: fields.app_max_bundle_size,\n      app_flags: fields.app_flags,\n      app_version:\n        fields.app_version_major +\n        '.' +\n        fields.app_version_minor +\n        '.' +\n        fields.app_version_patch,\n    };\n  }\n\n  async _reset(partial = false) {\n    await this._sendCommand(\n      Commands.INS_RESET,\n      partial ? 1 : 0,\n      0,\n      undefined,\n      TIMEOUT_CMD_NON_USER_INTERACTION\n    );\n  }\n\n  async _sendCommand(ins, p1, p2, data, timeout) {\n    const transport = this.transport;\n    try {\n      transport.setExchangeTimeout(timeout);\n      return await transport.send(CLA, ins, p1, p2, data);\n    } catch (error) {\n      // update the message, if status code is present\n      if (error.statusCode) {\n        error.message = getErrorMessage(error.statusCode) || error.message;\n      }\n      throw error;\n    }\n  }\n}\n\nexport default Iota;\n","function getStatusMessage(statusCode) {\n  switch (statusCode) {\n    // improve text of most common errors\n    case 0x9000: // SW_OK\n      return 'Success';\n    case 0x6700: // SW_INCORRECT_LENGTH\n      return 'Incorrect input length';\n    case 0x6a80: // SW_COMMAND_INVALID_DATA\n      return 'Incorrect data';\n    case 0x6b00: // SW_INCORRECT_P1P2\n      return 'Incorrect command parameter';\n    case 0x6c00: // SW_INCORRECT_LENGTH_P3\n      return 'Incorrect length specified in header';\n    case 0x6d00: // SW_INS_NOT_SUPPORTED\n      return 'Invalid INS command';\n    case 0x6e00: // SW_CLA_NOT_SUPPORTED\n      return 'Incorrect CLA (Wrong application opened)';\n    case 0x6900: // SW_COMMAND_NOT_ALLOWED\n      return 'Command not allowed (Command out of order)';\n    case 0x6982: // SW_SECURITY_STATUS_NOT_SATISFIED\n      return 'Security not satisfied (Device locked)';\n    case 0x6985: // SW_CONDITIONS_OF_USE_NOT_SATISFIED\n      return 'Condition of use not satisfied (Denied by the user)';\n    case 0x6401: // SW_COMMAND_TIMEOUT\n      return 'Security not satisfied (Timeout exceeded)';\n    case 0x69a1: // SW_BUNDLE_ERROR + INSECURE HASH\n      return 'Bundle error (Insecure hash)';\n    case 0x69a2: // SW_BUNDLE_ERROR + NON-ZERO BALANCE\n      return 'Bundle error (Non zero balance)';\n    case 0x69a3: // SW_BUNDLE_ERROR + INVALID META TX\n      return 'Bundle error (Invalid meta transaction)';\n    case 0x69a4: // SW_BUNDLE_ERROR + INVALID ADDRESS INDEX\n      return 'Bundle error (Invalid input address/index pair(s))';\n    case 0x69a5: // SW_BUNDLE_ERROR + ADDRESS REUSED\n      return 'Bundle error (Address reused)';\n\n    // Legacy exceptions\n    case 0x6984: // SW_COMMAND_INVALID_DATA\n      return 'Invalid input data';\n    case 0x6986: // SW_APP_NOT_INITIALIZED\n      return 'App has not been initialized by user';\n    case 0x6991: // SW_TX_INVALID_INDEX\n      return 'Invalid transaction index';\n    case 0x6992: // SW_TX_INVALID_ORDER\n      return 'Invalid transaction order (Output, Inputs, Change)';\n    case 0x6993: // SW_TX_INVALID_META\n      return 'Invalid meta transaction';\n    case 0x6994: // SW_TX_INVALID_OUTPUT\n      return 'Invalid output transaction (Output must come first)';\n  }\n\n  // unexpected exception thrown\n  if (0x6f00 <= statusCode && statusCode <= 0x6fff) {\n    return 'Internal error, please report';\n  }\n}\n\n/**\n * Provides meaningful responses to error status codes returned by IOTA Ledger app.\n * @param {Integer} statusCode - Error statusCodecode\n * @returns {String} String message corresponding to error code\n */\nexport function getErrorMessage(statusCode) {\n  const smsg = getStatusMessage(statusCode);\n  if (smsg) {\n    const statusCodeStr = statusCode.toString(16);\n\n    // set the message according to the status code\n    return `Ledger device: ${smsg} (0x${statusCodeStr})`;\n  }\n}\n"],"names":["validInteger","Joi","number","integer","validSecurity","min","max","validIndex","validValue","validBalance","validTrytes","string","regex","validTag","allow","validAddress","alternatives","length","validTransfers","array","items","object","address","required","tag","value","unknown","validInputs","balance","keyIndex","tags","optional","validRemainder","_settle","pact","state","s","_Pact","o","bind","v","then","observer","prototype","onFulfilled","onRejected","result","this","callback","e","_this","_isSettledPact","thenable","_for","test","update","body","stage","shouldContinue","updateValue","reject","_resumeAfterTest","_resumeAfterBody","_resumeAfterUpdate","Symbol","iterator","EMPTY_TAG","repeat","transport","decorateAppAPIMethods","config","undefined","security","pathArray","setActiveSeed","path","_this2","semver","satisfies","app_version","_createPubkeyInput","_createPubkeyInputLegacy","_createTxInput","_createTxInputLegacy","_setSeed","_reset","assert","Iota","_validatePath","_getAppConfig","getAddress","index","options","_assertInitialized","checksum","_publicKey","display","addChecksum","prepareTransfers","transfers","inputs","remainder","now","Date","_this6","func","arity","Error","_validateRemainder","_prepareTransfers","trytes","getAppVersion","_this8","getAppMaxBundleSize","_this10","app_max_bundle_size","bippath","fromString","toPathArray","message","_addSeedFields","struct","word8","word32Ule","_initSeedFields","fields","pathLength","setSeedInStruct","Struct","_this12","allocate","_sendCommand","buffer","pubkeyInStruct","response","pubkeyOutStruct","chars","setBuffer","reduce","a","i","payment","t","_sign","sliceLength","signInStruct","signOutStruct","word8Sle","signature","fragmentsRemaining","address_idx","tx_idx","tx_len","time","word64Sle","_transaction","txInStruct","timeout","txOutStruct","finalized","bundleHash","_getSignatureFragments","match","numSlices","_this20","_addSignatureFragmentsToBundle","bundle","tx","_this22","signatureFragments","signatureMessageFragment","shift","j","_signBundle","addressKeyIndices","_this24","target","check","_iteratorSymbol","step","_cycle","next","done","_fixup","TypeError","values","push","_forTo","obsoleteTag","currentIndex","lastIndex","timestamp","_hasDuplicateAddresses","set","Set","forEach","add","has","map","noChecksum","padEnd","_this26","Math","floor","Bundle","x","addEntry","addTrytes","finalize","bundleTrytes","transactionTrytes","reverse","_createAppConfigOutputLegacy","_createAppConfigOutput","_this28","getAppConfigOutStruct","app_flags","app_version_major","app_version_minor","app_version_patch","partial","ins","p1","p2","data","recover","setExchangeTimeout","send","error","statusCode","smsg","getStatusMessage","toString","getErrorMessage"],"mappings":"ofAEA,IAAMA,EAAeC,UAAIC,SAASC,UAC5BC,EAAgBJ,EAAaK,IAAI,GAAGC,IAAI,GACxCC,EAAaP,EAAaK,IAAI,GAAGC,IAAI,YACrCE,EAAaR,EAAaK,IAAI,GAAGC,IAAI,iBACrCG,EAAeT,EAAaK,IAAI,GAAGC,IAAI,iBAEvCI,EAAcT,UAAIU,SAASC,MAAM,aACjCC,EAAWH,EAAYI,MAAM,IAAIR,IAAI,IACrCS,EAAed,UAAIe,mBACvBN,EAAYO,OAA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