import { GetAddressFn } from "@ledgerhq/ledger-wallet-framework/bridge/getAddressWrapper"; import { GetAddressOptions } from "@ledgerhq/ledger-wallet-framework/derivation"; import { SignerContext } from "@ledgerhq/ledger-wallet-framework/signer"; import { address as TyphonAddress } from "@stricahq/typhonjs"; import { utils as TyphonUtils } from "@stricahq/typhonjs"; import { STAKING_ADDRESS_INDEX } from "./constants"; import { getBipPathFromString, getBipPathString } from "./logic"; import { getNetworkParameters } from "./networks"; import { CardanoSigner } from "./signer"; import { StakeChain } from "./types"; const resolver = (signerContext: SignerContext): GetAddressFn => { return async (deviceId: string, { path, verify, currency }: GetAddressOptions) => { const spendingPath = getBipPathFromString(path); const stakingPathString = getBipPathString({ account: spendingPath.account, chain: StakeChain.stake, index: STAKING_ADDRESS_INDEX, }); const networkParams = getNetworkParameters(currency.id); const r = await signerContext(deviceId, signer => signer.getAddress({ path, stakingPathString, networkParams, verify }), ); const address = TyphonUtils.getAddressFromHex( Buffer.from(r.addressHex, "hex"), ) as TyphonAddress.BaseAddress; return { address: address.getBech32(), // Here, we use publicKey hash, as cardano app doesn't export the public key publicKey: address.paymentCredential.hash.toString("hex"), path, }; }; }; export default resolver;