@faast/ethereum-payments
Version:
Library to assist in processing ethereum payments, such as deriving addresses and sweeping funds
98 lines • 4 kB
JavaScript
import * as t from 'io-ts';
import { enumCodec, extendCodec, Numeric, optional, } from '@faast/ts-common';
import { BaseTransactionInfo, BaseUnsignedTransaction, BaseSignedTransaction, BaseBroadcastResult, BaseConfig, ResolvedFeeOption, FeeOption, FeeOptionCustom, KeyPairsConfigParam, CreateTransactionOptions, } from '@faast/payments-common';
export var EthereumAddressFormat;
(function (EthereumAddressFormat) {
EthereumAddressFormat["Lowercase"] = "lowercase";
EthereumAddressFormat["Checksum"] = "checksum";
})(EthereumAddressFormat || (EthereumAddressFormat = {}));
export const EthereumAddressFormatT = enumCodec(EthereumAddressFormat, 'EthereumAddressFormat');
const keys = t.type({
pub: t.string,
prv: t.string,
});
const xkeys = t.type({
xprv: t.string,
xpub: t.string,
});
const OptionalString = optional(t.string);
const OptionalNumber = optional(t.number);
export const EthereumSignatory = t.type({
address: t.string,
keys,
xkeys,
}, 'EthereumSignatory');
export const EthereumPaymentsUtilsConfig = extendCodec(BaseConfig, {}, {
fullNode: OptionalString,
parityNode: OptionalString,
blockbookNode: OptionalString,
gasStation: OptionalString,
symbol: OptionalString,
name: OptionalString,
decimals: t.number,
providerOptions: t.any,
web3: t.any,
}, 'EthereumPaymentsUtilsConfig');
export const BaseEthereumPaymentsConfig = extendCodec(EthereumPaymentsUtilsConfig, {}, {
depositKeyIndex: OptionalNumber,
}, 'BaseEthereumPaymentsConfig');
export const HdEthereumPaymentsConfig = extendCodec(BaseEthereumPaymentsConfig, {
hdKey: t.string,
}, 'HdEthereumPaymentsConfig');
export const KeyPairEthereumPaymentsConfig = extendCodec(BaseEthereumPaymentsConfig, {
keyPairs: KeyPairsConfigParam,
}, 'KeyPairEthereumPaymentsConfig');
export const BaseErc20PaymentsConfig = extendCodec(BaseEthereumPaymentsConfig, {
tokenAddress: t.string,
}, {
masterAddress: t.string,
}, 'BaseErc20PaymentsConfig');
export const HdErc20PaymentsConfig = extendCodec(BaseErc20PaymentsConfig, {
hdKey: t.string,
}, 'HdErc20PaymentsConfig');
export const KeyPairErc20PaymentsConfig = extendCodec(BaseErc20PaymentsConfig, {
keyPairs: KeyPairsConfigParam,
}, 'KeyPairErc20PaymentsConfig');
export const Erc20PaymentsConfig = t.union([HdErc20PaymentsConfig, KeyPairErc20PaymentsConfig], 'Erc20PaymentsConfig');
export const EthereumPaymentsConfig = t.union([
HdEthereumPaymentsConfig, KeyPairEthereumPaymentsConfig, HdErc20PaymentsConfig, KeyPairErc20PaymentsConfig,
], 'EthereumPaymentsConfig');
export const EthereumTransactionOptions = extendCodec(CreateTransactionOptions, {}, {
data: t.string,
gas: Numeric,
proxyAddress: t.string,
}, 'EthereumTransactionOptions');
export const EthereumUnsignedTransaction = extendCodec(BaseUnsignedTransaction, {
amount: t.string,
fee: t.string,
}, 'EthereumUnsignedTransaction');
export const EthereumSignedTransaction = extendCodec(BaseSignedTransaction, {
data: t.type({
hex: t.string
}),
}, {}, 'EthereumSignedTransaction');
export const EthereumTransactionInfo = extendCodec(BaseTransactionInfo, {}, {}, 'EthereumTransactionInfo');
export const EthereumBroadcastResult = extendCodec(BaseBroadcastResult, {}, 'EthereumBroadcastResult');
export const EthereumResolvedFeeOption = extendCodec(ResolvedFeeOption, {
gasPrice: t.string,
}, 'EthereumResolvedFeeOption');
export const EthereumFeeOption = extendCodec(FeeOption, {}, {
isSweep: t.boolean,
}, 'EthereumFeeOption');
export const EthereumFeeOptionCustom = extendCodec(FeeOptionCustom, {}, {
isSweep: t.boolean,
}, 'EthereumFeeOption');
const BnRounding = t.union([
t.literal(1),
t.literal(2),
t.literal(3),
t.literal(4),
t.literal(5),
t.literal(6),
t.literal(7),
t.literal(8),
]);
export const BaseDenominationOptions = extendCodec(t.object, {}, {
rounding: BnRounding
}, 'BaseDenominationOptions');
//# sourceMappingURL=types.js.map