UNPKG

3.79 kBTypeScriptView Raw
1/// <reference types="node" />
2import { BigNumber } from "bignumber.js";
3import { ERC20_CLEAR_SIGNED_SELECTORS, ERC721_CLEAR_SIGNED_SELECTORS, ERC1155_CLEAR_SIGNED_SELECTORS } from "@ledgerhq/evm-tools/selectors/index";
4import type { Transaction } from "@ethersproject/transactions";
5import { LedgerEthTransactionResolution } from "./services/types";
6export { ERC20_CLEAR_SIGNED_SELECTORS, ERC721_CLEAR_SIGNED_SELECTORS, ERC1155_CLEAR_SIGNED_SELECTORS, };
7export declare const padHexString: (str: string) => string;
8export declare function splitPath(path: string): number[];
9export declare function hexBuffer(str: string): Buffer;
10export declare function maybeHexBuffer(str: string | null | undefined): Buffer | null | undefined;
11/**
12 * @ignore for the README
13 *
14 * Helper to convert an integer as a hexadecimal string with the right amount of digits
15 * to respect the number of bytes given as parameter
16 *
17 * @param int Integer
18 * @param bytes Number of bytes it should be represented as (1 byte = 2 caraters)
19 * @returns The given integer as an hexa string padded with the right number of 0
20 */
21export declare const intAsHexBytes: (int: number, bytes: number) => string;
22export declare const tokenSelectors: ERC20_CLEAR_SIGNED_SELECTORS[];
23export declare const nftSelectors: (ERC721_CLEAR_SIGNED_SELECTORS | ERC1155_CLEAR_SIGNED_SELECTORS)[];
24export declare const mergeResolutions: (resolutionsArray: Partial<LedgerEthTransactionResolution>[]) => LedgerEthTransactionResolution;
25/**
26 * @ignore for the README
27 *
28 * Ledger devices are returning v with potentially EIP-155 already applied when using legacy transactions.
29 * Because that v value is only represented as a single byte, we need to replicate what would be the
30 * overflow happening on the device while applying EIP-155 and recover the original parity.
31 *
32 * @param vFromDevice
33 * @param chainIdUint32
34 * @returns
35 */
36export declare const getParity: (vFromDevice: number, chainId: BigNumber, transactionType: Transaction["type"]) => 0 | 1;
37/**
38 * @ignore for the README
39 *
40 * Helper to convert a chainId from a BigNumber to a 4 bytes integer.
41 * ChainIds are uint256, but the device limits them to 4 bytes
42 *
43 * @param {Number|BigNumber} chainId
44 * @returns {Number}
45 */
46export declare const getChainIdAsUint32: (chainId: BigNumber | number) => number;
47/**
48 * @ignore for the README
49 *
50 * Depending on the transaction type you're trying to sign with the device, the v value will be different.
51 * For legacy transactions, the v value is used to store the chainId, and that chainId can be a uint256,
52 * and some math operation should be applied to it in order to comply with EIP-155 for replay attacks.
53 *
54 * In order to prevent breaking changes at the time, the `v` value has been kept as a single byte
55 * which forces us to replicate an overflow happening on the device to get the correct `v` value
56 *
57 * @param {number} vFromDevice
58 * @param {BigNumber} chainId
59 * @param {Transaction["type"]} transactionType
60 * @returns {string} hexa string of the v value
61 */
62export declare const getV: (vFromDevice: number, chainId: BigNumber, transactionType: Transaction["type"]) => string;
63/**
64 * @ignore for the README
65 *
66 * In order to prevent the device from considering a transaction RLP as complete before it actually is
67 * we need to split the RLP into chunks which could not be mistaken for a complete transaction.
68 * This is true for legacy transaction, where the `v` value is used to store the chainId
69 *
70 * @param {Buffer} transactionRlp
71 * @param {Buffer }derivationPath
72 * @param {Transaction["type"]} transactionType
73 *
74 * @returns {Buffer[]}
75 */
76export declare const safeChunkTransaction: (transactionRlp: Buffer, derivationPath: Buffer, transactionType: Transaction["type"]) => Buffer[];
77//# sourceMappingURL=utils.d.ts.map
\No newline at end of file