@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
33 lines • 1.29 kB
JavaScript
// Goal of this file is to provide utils for injecting device/signer dependency to coin-modules.
import { firstValueFrom, from } from "rxjs";
import { withDevice } from "../hw/deviceAccess";
/**
* Retrieve `transport` to provide it to the signer and give some sort of scope for which the `transport` will be valid.
* @param signerFactory
* @returns SignerContext
*/
export function executeWithSigner(signerFactory) {
return (deviceId, fn) => firstValueFrom(withDevice(deviceId)(transport => from(fn(signerFactory(transport)))));
}
/**
* Inject the `signer` so it can be used by the resolver function.
* @param signer
* @param coinResolver
* @returns Resolver
*/
export function createResolver(signerFactory, coinResolver) {
return (transport, opts) => {
const signerContext = (_, fn) => fn(signerFactory(transport));
return coinResolver(signerContext)("", opts);
};
}
/**
* Inject the `signer` so it can be used by the hw-signMessage function.
*/
export function createMessageSigner(signerFactory, messageSigner) {
return (transport, account, messageData) => {
const signerContext = (_, fn) => fn(signerFactory(transport));
return messageSigner(signerContext)("", account, messageData);
};
}
//# sourceMappingURL=setup.js.map