3 - Address derivation
Derive Address from device
First define the signer interface in dedicated libs/coin-module/coin-mycoin/src/types/signer.ts
file, which will reflect your embedded app js binding:
export type MyCoinAddress = {
address: string,
publicKey: string,
returnCode: number,
};
export type MyCoinSignature = {
signature: Buffer | null,
returnCode: number
};
export interface MyCoinSigner {
getAddress(path: string, display?: bool): Promise<MyCoinAddress>;
sign(path: string, message: string): Promise<MyCoinSignature>;
}
Then get an address from the device for MyCoin, by creating the hw-getAddress.ts
Resolver:
libs/coin-module/coin-mycoin/src/signer/getAddress.ts
:
import type { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
import type { SignerContext } from "@ledgerhq/coin-framework/signer";
import type { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
import type { MyCoinAddress, MyCoinSignature, MyCoinSigner } from "./signer";
const resolver = (
signerContext: SignerContext<MyCoinSigner, MyCoinAddress | MyCoinSignature>,
): GetAddressFn => {
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
const address = (await signerContext(deviceId, signer =>
signer.getAddress(path, verify),
)) as MyCoinAddress;
return {
address: address.address,
publicKey: address.pubKey,
path,
};
};
};
export default resolver;
Test that you can derive an address:
ledger-live getAddress --currency mycoin --path "44'/8008'/0'/0/0" --derivationMode ""
Derivation
Ledger Live uses the BIP44 derivation mode by default (as derivationMode=""
), which is standard and most common way for HD wallet.
If MyCoin has a conventional derivation path (BIP44), Ledger Live should already be able to derive an address correctly.
If you need to use another derivation mode:
Make changes to libs/ledger-live-common/src/derivation.ts
(opens in a new tab):
- Add a new derivation mode with
overridesDerivation
:
// const modes = Object.freeze({
// ...
mycoinbip44h: { // Hardened BIP44 for MyCoin
overridesDerivation: "44'/8008'/<account>'/0'/<address>'",
},
// });
- Add the mode to family in
legacyDerivations
:
// const legacyDerivations: $Shape<CryptoCurrencyConfig<DerivationMode[]>> = {
// ...
mycoin: ["mycoinbip44h"],
// };
- Disable the default use of BIP44 in
disableBIP44
:
// const disableBIP44 = {
// ...
mycoin: true,
// };
- Add the coin to
seedIdentifierPath
:
// const seedIdentifierPath = {
// ...
mycoin: `${purpose}'/${coinType}'/0'/0'/0'`,
// };
See Derivation documentation (opens in a new tab) for further details.
You can check that the derivationMode is correct by executing:
pnpm build:cli
pnpm run:cli getAddress --currency=mycoin --path="44'/8008'/0'/0/0" --derivationMode=""