UNPKG

@ledgerhq/coin-stacks

Version:
71 lines (62 loc) 2.32 kB
import getAddressWrapper from "@ledgerhq/ledger-wallet-framework/bridge/getAddressWrapper"; import { getSerializedAddressParameters, makeAccountBridgeReceive, makeScanAccounts, makeSync, updateTransaction, } from "@ledgerhq/ledger-wallet-framework/bridge/jsHelpers"; import { SignerContext } from "@ledgerhq/ledger-wallet-framework/signer"; import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live"; import { STACKS_DUMMY_ADDRESS } from "../constants"; import resolver from "../signer/index"; import type { Transaction, TransactionStatus, StacksSigner } from "../types"; import { broadcast } from "./broadcast"; import { createTransaction } from "./createTransaction"; import { estimateMaxSpendable } from "./estimateMaxSpendable"; import { getTransactionStatus } from "./getTransactionStatus"; import { prepareTransaction } from "./prepareTransaction"; import { buildSignOperation } from "./signOperation"; import { getAccountShape } from "./synchronization"; import { validateAddress } from "./validateAddress"; function buildCurrencyBridge(signerContext: SignerContext<StacksSigner>): CurrencyBridge { const getAddress = resolver(signerContext); const scanAccounts = makeScanAccounts({ getAccountShape, getAddressFn: getAddressWrapper(getAddress), }); return { scanAccounts, }; } const sync = makeSync({ getAccountShape }); function buildAccountBridge( signerContext: SignerContext<StacksSigner>, ): AccountBridge<Transaction, Account, TransactionStatus> { const getAddress = resolver(signerContext); const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress)); const signOperation = buildSignOperation(signerContext); return { estimateMaxSpendable, createTransaction, updateTransaction, getTransactionStatus, getEstimationRecipient: () => STACKS_DUMMY_ADDRESS, prepareTransaction, sync, receive, signOperation, signRawOperation: () => { throw new Error("signRawOperation is not supported"); }, broadcast, getSerializedAddressParameters, validateAddress, }; } export function createBridges(signerContext: SignerContext<StacksSigner>) { return { currencyBridge: buildCurrencyBridge(signerContext), accountBridge: buildAccountBridge(signerContext), }; }