Constructor
new TrezorInteraction(options)
Trezor interactions require knowing the bitcoin network they are for.
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
options |
object | options argument Properties
|
Example
import {TrezorInteraction} from "unchained-wallets";
// Simple subclass
class SimpleTrezorInteraction extends TrezorInteraction {
constructor({network, param}) {
super({network});
this.param = param;
}
connectParams() {
return [
TrezorConnect.doSomething, // Not a real TrezorConnect function...
{
// Many Trezor methods require the `coin` parameter. The
// value of `this.trezorCoin` is set appropriately based on the
// `network` provided in the constructor.
coin: this.trezorCoin,
// Pass whatever arguments are required
// by the TrezorConnect function being called.
param: this.param,
// ...
}
];
}
parsePayload(payload) {
return payload.someValue;
}
}
// usage
import {MAINNET} from "unchained-bitcoin";
const interaction = new SimpleTrezorInteraction({network: MAINNET, param: "foo"});
const result = await interaction.run();
console.log(result); // someValue from payload
Extends
Methods
connectParams() → {Array.<function(), Object>}
Override this method in a subclass to return a 2-element array.
The first element should be a functin to call, typically a
TrezorConnect method, e.g. TrezorConnect.getAddress.
The second element should be the parameters to pass to this function.
By default, the function passed just throws an error.
Returns:
the TrezorConnect parameters
- Type
- Array.<function(), Object>
messages() → {Array.<module:interaction.Message>}
Default messages are added asking the user to plug in their
Trezor device (device.connect) and about the TrezorConnect
popups (trezor.connect.generic).
Subclasses should override this method and add their own messages
(don't forget to call super()).
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
parsePayload(payload) → {Object}
Override this method in a subclass to parse the payload of a successful response from the device.
By default, the entire payload is returned.
Parameters:
| Name | Type | Description |
|---|---|---|
payload |
Object | the raw payload from the device response |
Returns:
- relevant or formatted data built from the raw payload
- Type
- Object
request() → {void}
Throws an error.
- Overrides:
- Source:
Throws:
An error since this is a direct interaction.
Returns:
- Type
- void
(async) run() → {Promise}
Awaits the call of this.method, passing in the output of
this.params().
If the call returns but is unsuccessful (result.success) is
false, will throw the returned error message. If some other
error is thrown, it will not be caught.
Otherwise it returns the result of passing result.payload to
this.parsePayload.
- Overrides:
- Source:
Returns:
handles the work of calling TrezorConnect
- Type
- Promise