UNPKG

@test-org122/hypernet-core

Version:

Hypernet Core. Represents the SDK for running the Hypernet Protocol.

97 lines 6.15 kB
import { HexString, IHypernetOfferDetails, Payment, PublicIdentifier, PullPayment, PushPayment, ResultAsync, SortedTransfers } from "@interfaces/objects"; import { InvalidParametersError, InvalidPaymentError, InvalidPaymentIdError, LogicalError, VectorError } from "@interfaces/objects/errors"; import { EPaymentState, EPaymentType, ETransferType, InsuranceState, ParameterizedState } from "@interfaces/types"; import { IBrowserNodeProvider, IConfigProvider, IFullTransferState, ILogUtils, IPaymentIdUtils, IPaymentUtils, ITimeUtils, IVectorUtils } from "@interfaces/utilities"; /** * A class for creating Hypernet-Payment objects from Vector transfers, verifying information * about payment Ids, sorting transfers, and other related stuff. */ export declare class PaymentUtils implements IPaymentUtils { protected configProvider: IConfigProvider; protected logUtils: ILogUtils; protected paymentIdUtils: IPaymentIdUtils; protected vectorUtils: IVectorUtils; protected browserNodeProvider: IBrowserNodeProvider; protected timeUtils: ITimeUtils; /** * Return an instance of PaymentUtils. */ constructor(configProvider: IConfigProvider, logUtils: ILogUtils, paymentIdUtils: IPaymentIdUtils, vectorUtils: IVectorUtils, browserNodeProvider: IBrowserNodeProvider, timeUtils: ITimeUtils); /** * Verifies that the paymentId provided has domain matching Hypernet's domain name. * @param paymentId the payment ID to check */ isHypernetDomain(paymentId: HexString): ResultAsync<boolean, InvalidPaymentIdError>; /** * Creates a 32 byte payment ID of format: * <domain-10-bytes><payment-type-6-bytes><UUID-16-bytes> * @param paymentType the payment type for the id - PUSH or PULL */ createPaymentId(paymentType: EPaymentType): ResultAsync<string, InvalidParametersError>; /** * Given a SortedTransfers object and associated data about the payment, return a PushPayment object. * @param paymentId the paymentId for the provided SortedTransfers * @param to the destination public id for the payment * @param from the sender public id for the payment * @param state the current payment state * @param sortedTransfers the set of SortedTransfers for this payment * @param metadata the IHypernetOfferDetails for this payment */ transfersToPushPayment(paymentId: string, to: PublicIdentifier, from: PublicIdentifier, state: EPaymentState, sortedTransfers: SortedTransfers): ResultAsync<PushPayment, Error>; /** * Given a SortedTransfers object and associated data about the payment, return a PullPayment object. * @param paymentId the paymentId for the provided SortedTransfers * @param to the destination public id for the payment * @param from the sender public id for the payment * @param state the current payment state * @param sortedTransfers the set of SortedTransfers for this payment * @param metadata the IHypernetOfferDetails for this payment */ transfersToPullPayment(paymentId: string, to: PublicIdentifier, from: PublicIdentifier, state: EPaymentState, sortedTransfers: SortedTransfers): ResultAsync<PullPayment, LogicalError>; /** * Given a set of Vector transfers that we /know/ are for one specific payment, * return the associated payment object. * @param paymentId the payment associated with the provided transfers * @param transfers the transfers as IFullTransferState * @param config instance of HypernetConfig * @param browserNode instance of IBrowserNode */ transfersToPayment(paymentId: string, transfers: IFullTransferState[]): ResultAsync<Payment, InvalidPaymentError | InvalidParametersError>; getPaymentState(sortedTransfers: SortedTransfers): EPaymentState; protected validateInsuranceTransfer(transfer: IFullTransferState<InsuranceState>, offerDetails: IHypernetOfferDetails): boolean; protected validatePaymentTransfer(transfer: IFullTransferState<ParameterizedState>, offerDetails: IHypernetOfferDetails): boolean; /** * Given an array of (unsorted) Vector transfers, return the corresponding Hypernet Payments * @param transfers array of unsorted Vector transfers as IFullTransferState * @param config instance of HypernetConfig * @param _context instance of HypernetContext * @param browserNode instance of the IBrowserNode */ transfersToPayments(transfers: IFullTransferState[]): ResultAsync<Payment[], InvalidPaymentError>; /** * Given a (vector) transfer @ IFullTransferState, return the transfer type (as ETransferType) * @param transfer the transfer to get the transfer type of * @param browserNode instance of a browserNode so that we can query for registered transfer addresses */ getTransferType(transfer: IFullTransferState): ResultAsync<ETransferType, VectorError | LogicalError>; /** * Exactly the same as getTransferType but also returns the source transfer, * useful when dealing with combine() and other contexts where it is easy * to loose track of which transfer you are getting the type for. */ getTransferTypeWithTransfer(transfer: IFullTransferState): ResultAsync<{ transferType: ETransferType; transfer: IFullTransferState; }, VectorError | Error>; /** * Given a paymentID and matching transfers for this paymentId, return the SortedTransfers object associated. * SortedTransfers is an object containing up to 1 of each of Offer, Insurance, Parameterized, PullRecord, and * the metadata associated with this payment (as IHypernetOfferDetails). * @param _paymentId the paymentId for the provided transfers * @param transfers the transfers to sort * @param browserNode instance of a browserNode so that we can query for registered transfer addresses */ sortTransfers(_paymentId: string, transfers: IFullTransferState[]): ResultAsync<SortedTransfers, InvalidPaymentError | VectorError | Error>; getEarliestDateFromTransfers(transfers: IFullTransferState[]): number; } //# sourceMappingURL=PaymentUtils.d.ts.map