// @ts-ignore import astraxApi from "@digitalbits-blockchain/astrax-api"; import { Networks, Transaction, TransactionBuilder } from "@digitalbits-blockchain/xdb-digitalbits-sdk"; import { HandlerSignTransactionParams, KeyTypeHandler } from "../types"; import { KeyType } from "../constants/keys"; export const astraxHandler: KeyTypeHandler = { keyType: KeyType.astrax, async signTransaction(params: HandlerSignTransactionParams) { const { transaction, key, custom } = params; if (key.privateKey !== "") { throw new Error( `Non-ledger key sent to ledger handler: ${JSON.stringify( key.publicKey )}` ); } try { const response = await astraxApi.signTransaction( transaction.toXDR(), custom && custom.network ? custom.network : undefined ); // fromXDR() returns type "Transaction | FeeBumpTransaction" and // signTransaction() doesn't like "| FeeBumpTransaction" type, so casting // to "Transaction" type. return TransactionBuilder.fromXDR( response, Networks.PUBLIC ) as Transaction; } catch (error: any) { throw new Error( `We couldn’t sign the transaction with Freighter. ${error.toString()}.` ); } } };