Class: LedgerSignMultisigTransaction

ledger.LedgerSignMultisigTransaction(options)

Returns a signature for a bitcoin transaction with inputs from one or many multisig addresses.

  • inputs is an array of UTXO objects from unchained-bitcoin
  • outputs is an array of TransactionOutput objects from unchained-bitcoin
  • bip32Paths is an array of (string) BIP32 paths, one for each input, identifying the path on this device to sign that input with

Constructor

new LedgerSignMultisigTransaction(options)

Parameters:
Name Type Description
options object

options argument

Properties
Name Type Attributes Description
network string

bitcoin network

inputs array.<object> <optional>

inputs for the transaction

outputs array.<object> <optional>

outputs for the transaction

bip32Paths array.<string> <optional>

BIP32 paths

psbt string <optional>

PSBT string encoded in base64

keyDetails object <optional>

Signing Key Details (Fingerprint + bip32 prefix)

returnSignatureArray boolean <optional>

return an array of signatures instead of a signed PSBT (useful for test suite)

Source:
Example
import {
  generateMultisigFromHex, TESTNET, P2SH,
} from "unchained-bitcoin";
import {LedgerSignMultisigTransaction} from "unchained-wallets";
const redeemScript = "5...ae";
const inputs = [
  {
    txid: "8d276c76b3550b145e44d35c5833bae175e0351b4a5c57dc1740387e78f57b11",
    index: 1,
    multisig: generateMultisigFromHex(TESTNET, P2SH, redeemScript),
    amountSats: '1234000'
  },
  // other inputs...
];
const outputs = [
  {
    amountSats: '1299659',
    address: "2NGHod7V2TAAXC1iUdNmc6R8UUd4TVTuBmp"
  },
  // other outputs...
];
const interaction = new LedgerSignMultisigTransaction({
  network: TESTNET,
  inputs,
  outputs,
  bip32Paths: ["m/45'/0'/0'/0", // add more, 1 per input],
});
const signature = await interaction.run();
console.log(signatures);
// ["ababab...", // 1 per input]

Extends

Methods

closeTransport() → {Promise}

Close the Transport to free the interface (E.g. could be used in another tab now that the interaction is over)

The way the pubkey/xpub/fingerprints are grabbed makes this a little tricky. Instead of re-writing how that works, let's just add a way to explicitly close the transport.

Overrides:
Source:
Returns:
  • promise to close the transport
Type
Promise

messages() → {Array.<module:interaction.Message>}

Adds messages describing the signing flow.

Overrides:
Source:
Returns:

messages for this interaction

Type
Array.<module:interaction.Message>

parse() → {void}

Throws an error.

Overrides:
Source:
Throws:

An error since this is a direct interaction.

Returns:
Type
void

request() → {void}

Throws an error.

Overrides:
Source:
Throws:

An error since this is a direct interaction.

Returns:
Type
void

run() → {Array.<string>|string}

See https://github.com/LedgerHQ/ledgerjs/tree/master/packages/hw-app-btc#signp2shtransaction.

Input signatures produced will always have a trailing ...01 SIGHASH_ALL byte.

Overrides:
Source:
Returns:

array of input signatures, one per input or PSBT in Base64

Type
Array.<string> | string

withApp(callback) → {Promise}

Can be called by a subclass during its run() method.

Creates a transport layer connection, initializes a bitcoin app object, and passes control to the callback function, with the app API as the first argument to the function and the transport API as the second.

See the Ledger API for general information or the bitcoin app API for examples of API calls.

Parameters:
Name Type Description
callback function
  • accepts two parameters, app and transport, which are the Ledger APIs for the bitcoin app and the transport layer, respectively.
Overrides:
Source:
Returns:

does the work of setting up an app instance (and transport connection)

Type
Promise
Example
async run() {
  return await this.withApp(async (app, transport) => {
    return app.doSomething(); // Not a real Ledger bitcoin app API call
  });
}

(async) withTransport(callback) → {Promise}

Can be called by a subclass during its run() method.

Creates a transport layer connection and passes control to the callback function, with the transport API as the first argument to the function.

See the Ledger API for general information or a specific transport API for examples of API calls.

Parameters:
Name Type Description
callback function
  • asynchronous function accepting a single parameter transport
Overrides:
Source:
Returns:

does the work of setting up a transport connection

Type
Promise
Example
async run() {
  return await this.withTransport(async (transport) => {
    return transport.doSomething(); // Not a real Ledger transport API call
  });
}