-
Notifications
You must be signed in to change notification settings - Fork 54
/
tx.ts
44 lines (41 loc) · 1.51 KB
/
tx.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
44
import * as Trezor from 'trezor-connect';
import { Cardano } from '@cardano-sdk/core';
import { TrezorTxTransformerContext } from '../types';
import { util as depricated } from '@cardano-sdk/key-management';
import { mapTxIns } from './txIn';
/**
* Temporary transformer function that returns a partial
* trezor.CardanoSignTransaction object which can be merged
* into the extisting implementation (later we should refactor
* this function to the Transformer interface like in the
* hardware-ledger package)
*/
const trezorTxTransformer = async (
body: Cardano.TxBody,
context: TrezorTxTransformerContext
): Promise<Partial<Trezor.CardanoSignTransaction>> => ({
fee: body.fee.toString(),
inputs: await mapTxIns(body.inputs, context)
});
/**
* Temporary props type extending the existing TxToTrezorProps
* and adding the core Cardano.TxBody so we can pass it to our
* override implementations.
*/
type TxToTrezorProps = depricated.TxToTrezorProps & {
cardanoTxBody: Cardano.TxBody;
};
/**
* Takes a core transaction and context data necessary to transform
* it into a trezor.CardanoSignTransaction
*/
export const txToTrezor = async (props: TxToTrezorProps): Promise<Trezor.CardanoSignTransaction> => ({
// First run the depricated trezor transformers
...(await depricated.txToTrezor(props)),
// Then override them with our new implementations
...(await trezorTxTransformer(props.cardanoTxBody, {
chainId: props.chainId,
inputResolver: props.inputResolver,
knownAddresses: props.knownAddresses
}))
});