Coder Social home page Coder Social logo

Help getting trezor working about trezor-link HOT 2 CLOSED

trezor avatar trezor commented on May 30, 2024
Help getting trezor working

from trezor-link.

Comments (2)

MarcZenn avatar MarcZenn commented on May 30, 2024

Has there been any progress on this? I'm attempting to run mocha chai unit tests and am also encountering this issue:

> mocha --require source-map-support/register --require make-promises-safe lib/test/unit/**/*_test.js --timeout 10000 --bail --exit


/Users/marcmartinez/Desktop/0x-monorepo/node_modules/trezor-connect/lib/data/ConnectSettings.js:39
    supportedBrowser: !/Trident|MSIE/.test(navigator.userAgent),
                                           ^
ReferenceError: navigator is not defined

Here's my implementation in TS:

export class TrezorSubprovider extends BaseWalletSubprovider {
    private readonly _publicKeyPath: string;
    private _cachedAccounts: string[];
    // NOTE:: trezor-connect module currently runs in browser only https://github.com/trezor/connect/issues/248
    private _runningInBrowser: boolean;
    /**
     * Instantiates a TrezorSubprovider. Defaults to private key path set to `44'/60'/0'`.
     * @return TrezorSubprovider instance
     */
    constructor() {
        super();
        this._publicKeyPath = PRIVATE_KEY_PATH;
        this._cachedAccounts = [];
        this._runningInBrowser = typeof window === 'undefined' ? false : true;
    }
    /**
     * Retrieve a users Trezor account. The accounts are private key path derived, This method
     * is automatically called when issuing a `eth_accounts` JSON RPC request via your providerEngine
     * instance.
     * @return An array of accounts
     */
    public async getAccountsAsync(): Promise<string[]> {
        if (!this._runningInBrowser) {
            throw new Error(WalletSubproviderErrors.MustRunInBrowser);
        }
        if (this._cachedAccounts.length) {
            return this._cachedAccounts;
        }
        const accounts: string[] = [];
        const response: TrezorConnectResponse =  TrezorConnect.ethereumGetAddress({ path: this._publicKeyPath, showOnTrezor: true  });

        if (response.success) {
            const payload: TrezorGetAddressResponsePayload  = response.payload;
            accounts.push(payload.address);
            this._cachedAccounts = accounts;
        } else {
            const payload: TrezorResponseErrorPayload = response.payload;
            throw new Error(payload.error);
        }

        return accounts;
    }
}

from trezor-link.

tsusanka avatar tsusanka commented on May 30, 2024

Outdated, we have moved trezor-link to trezor-suite monorepo, please open a new issue there if needed.

from trezor-link.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.