@ledgerhq/coin-hedera
Version:
Ledger Hedera Coin integration
35 lines • 1.5 kB
JavaScript
import { WrongDeviceForAccount } from "@ledgerhq/errors";
import { isSegwitDerivationMode } from "@ledgerhq/ledger-wallet-framework/derivation";
import { Observable } from "rxjs";
/* this is due to libs/coin-modules/coin-hedera/src/hw-getAddress.ts
r.address is actually the public key, to check if we're on another device
we resort to this check instead
we rely on seedIdentifier being the public key for Hedera accounts
TODO: document where the seedIdentifier for hedera is set
looks like it's set to the publickey in makeScanAccount here: libs/ledger-wallet-framework/src/bridge/jsHelpers.ts */
export const receive = (getAddress) => (account, { deviceId }) => new Observable(o => {
void (async function () {
try {
const r = await getAddress(deviceId, {
derivationMode: account.derivationMode,
currency: account.currency,
path: account.freshAddressPath,
segwit: isSegwitDerivationMode(account.derivationMode),
});
if (r.publicKey !== account.seedIdentifier) {
throw new WrongDeviceForAccount();
}
o.next({
address: account.freshAddress,
path: account.freshAddressPath,
publicKey: r.publicKey,
});
o.complete();
}
catch (err) {
o.error(err);
}
})();
});
export default receive;
//# sourceMappingURL=receive.js.map