Bitcoin
getPublicKey
Method testing tool

Get public key

Retrieves BIP32 extended public derived by given BIP32 path. User is presented with a description of the requested key and asked to confirm the export.

const result = await TrezorConnect.getPublicKey(params);

Params

Optional common params

Exporting single public key

path

String | Array<Number>

Derivation Path. minimum length is 1

showOnTrezor

Boolean

Display the result on the Trezor device. Default is false

suppressBackupWarning

Boolean

By default, this method will emit an event to show a warning if the wallet does not have a backup. This option suppresses the message.

chunkify

Boolean

Display the result in chunks for better readability. Default is false

coin

String

determines network definition specified in coins.json file. Coin shortcut, name or label can be used. If coin is not set API will try to get network definition from path.

crossChain

Boolean

Advanced feature. Use it only if you are know what you are doing. Allows to generate address between chains. For example Bitcoin path on Litecoin network will display cross chain address in Litecoin format.

scriptType

"SPENDADDRESS" | "SPENDMULTISIG" | "SPENDWITNESS" | "SPENDP2SHWITNESS" | "SPENDTAPROOT"

used to distinguish between various address formats (non-segwit, segwit, etc.).

ignoreXpubMagic

Boolean

ignore SLIP-0132 XPUB magic, use xpub/tpub prefix for all account types.

ecdsaCurveName

String

ECDSA curve name to use

unlockPath

UnlockPath

the result of TrezorConnect.unlockPath method

address_n

Array<Number>

mac

String

Exporting bundle of public keys

bundle

Array of Objects with above schema


Example

Return public key of fifth bitcoin account:

TrezorConnect.getPublicKey({
    path: "m/49'/0'/4'",
    coin: 'btc',
});

Return a bundle of public keys for multiple bitcoin accounts:

TrezorConnect.getPublicKey({
    bundle: [
        { path: "m/49'/0'/0'" }, // account 1
        { path: "m/49'/0'/1'" }, // account 2
        { path: "m/49'/0'/2'" }, // account 3
    ],
});

Result

HDNodeResponse type (opens in a new tab)

Result with only one public key

{
    success: true,
    payload: {
        path: Array<number>, // hardended path
        serializedPath: string, // serialized path
        xpub: string,        // xpub in legacy format
        xpubSegwit?: string, // optional for segwit accounts: xpub in segwit format
        chainCode: string,   // BIP32 serialization format
        childNum: number,    // BIP32 serialization format
        publicKey: string,   // BIP32 serialization format
        fingerprint: number, // BIP32 serialization format
        depth: number,       // BIP32 serialization format
    }
}

Read more about BIP32 serialization format (opens in a new tab)

Result with bundle of public keys

{
    success: true,
    payload: [
        { path, serializedPath, xpub, xpubSegwit?, chainCode, childNum, publicKey, fingerprint, depth }, // account 1
        { path, serializedPath, xpub, xpubSegwit?, chainCode, childNum, publicKey, fingerprint, depth }, // account 2
        { path, serializedPath, xpub, xpubSegwit?, chainCode, childNum, publicKey, fingerprint, depth }  // account 3
    ]
}

Error

{
    success: false,
    payload: {
        error: string // error message
    }
}