Caravan Documentation
    Preparing search index...

    Class TrezorConfirmMultisigAddress

    Base class for interactions with Trezor hardware wallets.

    Assumes we are using TrezorConnect to talk to the device.

    Subclasses must implement a method this.connectParams which returns a 2-element array. The first element of this array should be a TrezorConnect method to use (e.g. - TrezorConnect.getAddress). The second element of this array should be the parameters to pass to the given TrezorConnect method.

    Errors thrown when calling TrezorConnect are not caught, so users of this class (and its subclasses) should use try...catch as always.

    Unsuccessful responses (the request succeeded but the Trezor device returned an error message) are intercepted and thrown as errors. This allows upstream try...catch blocks to intercept errors & failures uniformly.

    Subclasses may implement the parse(payload) method which accepts the response payload object and returns the relevant data.

    Subclasses will also want to implement a messages() method to manipulate the messages returned to the user for each interaction.

    import {TrezorInteraction} from "@caravan/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 {Network} from "@caravan/bitcoin";
    const interaction = new SimpleTrezorInteraction({network: Network.MAINNET, param: "foo"});
    const result = await interaction.run();
    console.log(result); // someValue from payload

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    bip32Path: string
    direct: boolean
    environment: Parser
    multisig: any
    network: null | Network
    publicKey: string
    trezorCoin: string

    Methods

    • Returns
          | (
              | {
                  (params: Params<{}>): Response<Address>;
                  (params: BundledParams<{}>): Response<Address[]>;
              }
              | {
                  bundle: (
                      | {
                          address?: undefined;
                          coin: string;
                          crossChain: boolean;
                          multisig?: undefined;
                          path: string;
                          scriptType?: undefined;
                          showOnTrezor: boolean;
                      }
                      | {
                          address: any;
                          coin: string;
                          crossChain: boolean;
                          multisig: { m: any; pubkeys: any };
                          path: string;
                          scriptType: string;
                          showOnTrezor: boolean;
                      }
                  )[];
              }
          )[]
          | (
              | {
                  (params: Params<{}>): Response<Address>;
                  (params: BundledParams<{}>): Response<Address[]>;
              }
              | {
                  address: any;
                  coin: string;
                  crossChain: boolean;
                  multisig: { m: any; pubkeys: any };
                  path: string;
                  scriptType: string;
                  showOnTrezor: boolean;
              }
          )[]

    • Subclasses can override this method to indicate they are not supported.

      This method has access to whatever options may have been passed in by the constructor as well as the ability to interact with this.environment to determine whether the functionality is supported. See the Bowser documentation for more details: https://github.com/lancedikson/bowser

      Returns boolean

      isSupported() {
      return this.environment.satisfies({
      * declare browsers per OS
      windows: {
      "internet explorer": ">10",
      },
      macos: {
      safari: ">10.1"
      },

      * per platform (mobile, desktop or tablet)
      mobile: {
      safari: '>=9',
      'android browser': '>3.10'
      },

      * or in general
      chrome: "~20.1.1432",
      firefox: ">31",
      opera: ">=22",

      * also supports equality operator
      chrome: "=20.1.1432", * will match particular build only

      * and loose-equality operator
      chrome: "~20", * will match any 20.* sub-version
      chrome: "~20.1" * will match any 20.1.* sub-version (20.1.19 as well as 20.1.12.42-alpha.1)
      });
      }
    • Return messages filtered by the given options.

      Multiple options can be given at once to filter along multiple dimensions.

      Parameters

      • __namedParameters: MessageMethodArgs

      Returns Message[]

      import {PENDING, ACTIVE} from "@caravan/bitcoin";
      // Create any interaction instance
      interaction.messages().forEach(msg => console.log(msg));
      { code: "device.connect", state: "pending", level: "info", text: "Please plug in your device."}
      { code: "device.active", state: "active", level: "info", text: "Communicating with your device..."}
      { code: "device.active.warning", state: "active", level: "warning", text: "Your device will warn you about...", version: "2.x"}
      interaction.messagesFor({state: PENDING}).forEach(msg => console.log(msg));
      { code: "device.connect", state: "pending", level: "info", text: "Please plug in your device."}
      interaction.messagesFor({code: ACTIVE}).forEach(msg => console.log(msg));
      { code: "device.active", state: "active", level: "info", text: "Communicating with your device..."}
      { code: "device.active.warning", state: "active", level: "warning", text: "Your device will warn you about...", version: "2.x"}
      interaction.messagesFor({version: /^2/}).forEach(msg => console.log(msg));
      { code: "device.active", state: "active", level: "warning", text: "Your device will warn you about...", version: "2.x"}
    • 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.

      Returns Promise<any>