-
Notifications
You must be signed in to change notification settings - Fork 332
/
setup.ts
43 lines (37 loc) · 1.75 KB
/
setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Goal of this file is to inject all necessary device/signer dependency to coin-modules
import { createBridges } from "@ledgerhq/coin-cosmos/bridge/index";
import makeCliTools from "@ledgerhq/coin-cosmos/cli";
import { CosmosCoinConfig } from "@ledgerhq/coin-cosmos/config";
import cosmosResolver from "@ledgerhq/coin-cosmos/hw-getAddress";
import { CosmosAccount, Transaction, TransactionStatus } from "@ledgerhq/coin-cosmos/types/index";
import { CosmosSigner } from "@ledgerhq/coin-cosmos/types/signer";
import Cosmos from "@ledgerhq/hw-app-cosmos";
import Transport from "@ledgerhq/hw-transport";
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
import type { Bridge } from "@ledgerhq/types-live";
import { CosmosApp } from "@zondax/ledger-cosmos-js";
import { CreateSigner, createResolver, executeWithSigner } from "../../bridge/setup";
import { getCurrencyConfiguration } from "../../config";
import { Resolver } from "../../hw/getAddress/types";
const createSigner: CreateSigner<CosmosSigner> = (transport: Transport) => {
const cosmos = new CosmosApp(transport);
const hwCosmos = new Cosmos(transport);
return {
getAddressAndPubKey: cosmos.getAddressAndPubKey.bind(cosmos),
sign: cosmos.sign.bind(cosmos),
getAddress: hwCosmos.getAddress.bind(hwCosmos),
};
};
const getCurrencyConfig = (currency?: CryptoCurrency) => {
if (!currency) {
throw new Error("No currency provided");
}
return getCurrencyConfiguration<CosmosCoinConfig>(currency);
};
const bridge: Bridge<Transaction, CosmosAccount, TransactionStatus> = createBridges(
executeWithSigner(createSigner),
getCurrencyConfig,
);
const resolver: Resolver = createResolver(createSigner, cosmosResolver);
const cliTools = makeCliTools();
export { bridge, cliTools, resolver };