Constructor
new LedgerExportHDNode(options, bip32Path)
Requires a valid BIP32 path to the node to export.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | options argument |
bip32Path |
string | the BIP32 path for the HD node |
Example
import {MAINNET} from "unchained-bitcoin";
import {LedgerExportHDNode} from "unchained-wallets";
const interaction = new LedgerExportHDNode({network: MAINNET, bip32Path: "m/48'/0'/0'/2'/0"});
const node = await interaction.run();
console.log(node);
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
(async) getFingerprint(root) → {string}
Get fingerprint from parent pubkey. This is useful for generating xpubs which need the fingerprint of the parent pubkey
Optionally get root fingerprint for device. This is useful for keychecks and necessary for PSBTs
Parameters:
Name | Type | Default | Description |
---|---|---|---|
root |
boolean | false | fingerprint or not |
Returns:
fingerprint
- Type
- string
hasBIP32PathWarning() → {boolean}
Returns whether or not the Ledger device will display a warning to the user about an unusual BIP32 path.
A "usual" BIP32 path is exactly 5 segments long. The segments have the following constraints:
- Segment 1: Must be equal to
44'
- Segment 2: Can have any value
- Segment 3: Must be between
0'
and100'
- Segment 4: Must be equal to
0
- Segment 5: Must be between
0 and 50000
Any other kind of path is considered unusual and will trigger the warning.
Returns:
whether a BIP32 path warning will be displayed
- Type
- boolean
messages() → {Array.<module:interaction.Message>}
Adds messages related to the warnings Ledger devices produce on various BIP32 paths.
- 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() → {object}
- Overrides:
- Source:
Returns:
the HD node object.
- Type
- object
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 |
|
- 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 |
|
- 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
});
}