0

I'm using the following node version:

> node -v
v8.9.3

And I have used Ledger to generate an Address using the following code:

const TransportHid = require("@ledgerhq/hw-transport-node-hid").default;
const AppBtc = require("@ledgerhq/hw-app-btc").default;

TransportHid.create()
  .then(async transport => {
    if (!transport) return console.log("err: Unable to establish connection");
    var btc = new AppBtc(transport);

    btc
      .getWalletPublicKey("0'/123'/0/0")
      .then(function(result) {
        console.log("Result\n:", result);
      })
      .catch(function(error) {
        console.log(error);
      });
  })
  .catch(err => console.log(err));

It returns the following:

dev 2c97 / 1 : usage_page:4800, usage:4449
dev 2c97 / 1 : usage_page:7761, usage:6800
dev 46d / c31d : usage_page:0, usage:0
dev 46d / c31d : usage_page:0, usage:101
dev 46d / c077 : usage_page:40, usage:0
dev 2c97 / 1 : usage_page:4800, usage:4449
dev 2c97 / 1 : usage_page:7761, usage:6800
dev 46d / c31d : usage_page:3f30, usage:291
dev 46d / c31d : usage_page:ff, usage:201
dev 46d / c077 : usage_page:40, usage:0
dev 2c97 / 1 : usage_page:4800, usage:4449
dev 2c97 / 1 : usage_page:7761, usage:6800
dev 46d / c31d : usage_page:0, usage:0
dev 46d / c31d : usage_page:201, usage:102
dev 46d / c077 : usage_page:40, usage:0
Result
: { publicKey: '045986874598bfa823ffc401296f0cc77a00b330d9a113845068036b912c69498418cb5ca1f00c53e2a6249e97842d5e87bb728cc120f6a52fee27806c82e738e3',
  bitcoinAddress: 'mq1yGi1Di58AFNkEYFNvyoHNcRCfFVEKAe',
  chainCode: 'a942949e80f0073a6ed106a716e2214373a78bad77cb96717e5c37fa76a5bb50' }

I sent some testnet BTC to this address using this faucet (https://testnet.manu.backend.hamburg/faucet).

Then I created a rawTx from the UTXO (whose object I got from the following insight API- https://testnet.blockexplorer.com/api/addr/mq1yGi1Di58AFNkEYFNvyoHNcRCfFVEKAe/utxo)

I calculated the following rawTx using bitcore-

010000000128e43e34d06366d0a4f4e0818660f49298dbd2827fdd219ed97096e7034e9a9a0000000000ffffffff0288f50400000000001976a914e722e7bc42cf04b132986b86258914b48b53122088ac5828b907000000001976a914683602a4deb0bfed1d3bdc160fc0c5d1076879ea88ac00000000

You can decode it here- https://live.blockcypher.com/btc/decodetx/

Then I used the following code to sign my transaction using createPaymentTransactionNew method for path 0'/123'/0/0. Same path owns the UTXO which I used as input to create my rawTx:

const TransportHid = require("@ledgerhq/hw-transport-node-hid").default;
const AppBtc = require("@ledgerhq/hw-app-btc").default;

TransportHid.create()
  .then(async transport => {
    if (!transport) return console.log("err: Unable to establish connection");
    var btc = new AppBtc(transport);

    const rawtx =
      "010000000128e43e34d06366d0a4f4e0818660f49298dbd2827fdd219ed97096e7034e9a9a0000000000ffffffff0288f50400000000001976a914e722e7bc42cf04b132986b86258914b48b53122088ac5828b907000000001976a914683602a4deb0bfed1d3bdc160fc0c5d1076879ea88ac00000000";
    const bufferedInput = await btc.splitTransaction(rawtx);

    const outputScriptHex = await btc
      .serializeTransactionOutputs(bufferedInput)
      .toString("hex");

    btc
      .createPaymentTransactionNew(
        [[bufferedInput, 0]],
        ["0'/123'/0/0"],
        "0'/123'/0/0",
        outputScriptHex
      )
      .then(console.log)
      .catch(console.log);
  })
  .catch(err => console.log(err));

When I use it this way it returns the following Error, when I run my code for the first time:

{ Error
    at new TransportStatusError (/home/rails/work/practise/ledger/node_modules/@ledgerhq/hw-transport/lib/Transport.js:152:16)
    at TransportNodeHid._callee$ (/home/rails/work/practise/ledger/node_modules/@ledgerhq/hw-transport/lib/Transport.js:205:23)
    at tryCatch (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as next] (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/home/rails/work/practise/ledger/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /home/rails/work/practise/ledger/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
    at <anonymous>
  name: 'TransportStatusError',
  message: 'Ledger device: Internal error, please report (0x6f01)',
  stack: 'Error\n    at new TransportStatusError (/home/rails/work/practise/ledger/node_modules/@ledgerhq/hw-transport/lib/Transport.js:152:16)\n    at TransportNodeHid._callee$ (/home/rails/work/practise/ledger/node_modules/@ledgerhq/hw-transport/lib/Transport.js:205:23)\n    at tryCatch (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:62:40)\n    at Generator.invoke [as _invoke] (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:296:22)\n    at Generator.prototype.(anonymous function) [as next] (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:114:21)\n    at step (/home/rails/work/practise/ledger/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)\n    at /home/rails/work/practise/ledger/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13\n    at <anonymous>',
  statusCode: 28417,
  statusText: 'UNKNOWN_ERROR' }

It arises somewhere while calling send in this line- https://github.com/LedgerHQ/ledgerjs/blob/0b3c75e182b7219299e468fc4dd692577d3801fe/packages/hw-app-btc/src/Btc.js#L129

When I re-run my code the Ledger returns HALTED STATUS, It also returns the same status for any other function I call. The error looks like this:

{ Error
    at new TransportStatusError (/home/rails/work/practise/ledger/node_modules/@ledgerhq/hw-transport/lib/Transport.js:152:16)
    at TransportNodeHid._callee$ (/home/rails/work/practise/ledger/node_modules/@ledgerhq/hw-transport/lib/Transport.js:205:23)
    at tryCatch (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as next] (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/home/rails/work/practise/ledger/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /home/rails/work/practise/ledger/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
    at <anonymous>
  name: 'TransportStatusError',
  message: 'Ledger device: Internal error, please report (0x6faa)',
  stack: 'Error\n    at new TransportStatusError (/home/rails/work/practise/ledger/node_modules/@ledgerhq/hw-transport/lib/Transport.js:152:16)\n    at TransportNodeHid._callee$ (/home/rails/work/practise/ledger/node_modules/@ledgerhq/hw-transport/lib/Transport.js:205:23)\n    at tryCatch (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:62:40)\n    at Generator.invoke [as _invoke] (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:296:22)\n    at Generator.prototype.(anonymous function) [as next] (/home/rails/work/practise/ledger/node_modules/regenerator-runtime/runtime.js:114:21)\n    at step (/home/rails/work/practise/ledger/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)\n    at /home/rails/work/practise/ledger/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13\n    at <anonymous>',
  statusCode: 28586,
  statusText: 'HALTED' }

It also returns an error when I call send function of transport object.

I have used createPaymentTransactionNew function as detailed in your documentation, but it still error, I think it is an issue with Ledger's code. I used the following dependencies:

"@ledgerhq/hw-app-btc": "^4.17.0",
"@ledgerhq/hw-app-eth": "^4.19.0",
"@ledgerhq/hw-transport-node-hid": "^4.18.0",
"babel-runtime": "^6.26.0",
"bip32": "^0.1.0",
"bitcoinjs-lib": "^3.3.2",
"bitcore-lib": "^0.15.0"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.