@test-org122/hypernet-core
Version:
Hypernet Core. Represents the SDK for running the Hypernet Protocol.
170 lines • 9.82 kB
TypeScript
import { IAccountService, IDevelopmentService, ILinkService, IMerchantService, IPaymentService } from "@interfaces/business";
import { IAccountsRepository, ILinkRepository, IMerchantConnectorRepository, IPaymentRepository } from "@interfaces/data";
import { IHypernetCore } from "@interfaces/IHypernetCore";
import { Balances, BigNumber, ControlClaim, EthereumAddress, ExternalProvider, HypernetConfig, HypernetLink, Payment, PublicIdentifier, PullPayment, PushPayment } from "@interfaces/objects";
import { AcceptPaymentError, BalancesUnavailableError, BlockchainUnavailableError, CoreUninitializedError, InsufficientBalanceError, LogicalError, MerchantValidationError, PersistenceError, RouterChannelUnknownError, VectorError } from "@interfaces/objects/errors";
import { EBlockchainNetwork } from "@interfaces/types";
import { IBlockchainProvider, IBlockchainUtils, IBrowserNodeProvider, IConfigProvider, IContextProvider, ILinkUtils, ILocalStorageUtils, ILogUtils, IPaymentIdUtils, IPaymentUtils, ITimeUtils, IVectorUtils } from "@interfaces/utilities";
import { IVectorListener } from "@interfaces/api";
import { Subject } from "rxjs";
import { Result, ResultAsync } from "neverthrow";
import { IAjaxUtils } from "@test-org122/utils";
import { IBrowserNodeFactory, IMerchantConnectorProxyFactory } from "@interfaces/utilities/factory";
/**
* The top-level class-definition for Hypernet Core.
*/
export declare class HypernetCore implements IHypernetCore {
onControlClaimed: Subject<ControlClaim>;
onControlYielded: Subject<ControlClaim>;
onPushPaymentProposed: Subject<PushPayment>;
onPushPaymentUpdated: Subject<PushPayment>;
onPullPaymentProposed: Subject<PullPayment>;
onPushPaymentReceived: Subject<PushPayment>;
onPullPaymentUpdated: Subject<PullPayment>;
onPullPaymentApproved: Subject<PullPayment>;
onBalancesChanged: Subject<Balances>;
onMerchantAuthorized: Subject<string>;
onAuthorizedMerchantUpdated: Subject<string>;
onAuthorizedMerchantActivationFailed: Subject<string>;
protected timeUtils: ITimeUtils;
protected blockchainProvider: IBlockchainProvider;
protected configProvider: IConfigProvider;
protected contextProvider: IContextProvider;
protected browserNodeProvider: IBrowserNodeProvider;
protected vectorUtils: IVectorUtils;
protected paymentUtils: IPaymentUtils;
protected linkUtils: ILinkUtils;
protected paymentIdUtils: IPaymentIdUtils;
protected logUtils: ILogUtils;
protected ajaxUtils: IAjaxUtils;
protected blockchainUtils: IBlockchainUtils;
protected localStorageUtils: ILocalStorageUtils;
protected merchantConnectorProxyFactory: IMerchantConnectorProxyFactory;
protected browserNodeFactory: IBrowserNodeFactory;
protected accountRepository: IAccountsRepository;
protected linkRepository: ILinkRepository;
protected paymentRepository: IPaymentRepository;
protected merchantConnectorRepository: IMerchantConnectorRepository;
protected accountService: IAccountService;
protected paymentService: IPaymentService;
protected linkService: ILinkService;
protected developmentService: IDevelopmentService;
protected merchantService: IMerchantService;
protected vectorAPIListener: IVectorListener;
protected _initializeResult: ResultAsync<void, LogicalError> | null;
protected _initialized: boolean;
protected _initializePromise: Promise<void>;
protected _initializePromiseResolve: (() => void) | null;
protected _inControl: boolean;
/**
* Returns an instance of HypernetCore.
* @param network the network to attach to
* @param config optional config, defaults to localhost/dev config
*/
constructor(network?: EBlockchainNetwork, config?: HypernetConfig, externalProvider?: ExternalProvider);
/**
* Returns the initialized status of this instance of Hypernet Core.
*/
initialized(): Result<boolean, LogicalError>;
waitInitialized(): ResultAsync<void, LogicalError>;
/**
* Whether or not this instance of Hypernet Core is currently the one in control.
*/
inControl(): Result<boolean, LogicalError>;
/**
* Returns a list of Ethereum accounts associated with this instance of Hypernet Core.
*/
getEthereumAccounts(): ResultAsync<string[], BlockchainUnavailableError>;
/**
* Returns the (vector) pubId associated with this instance of HypernetCore.
*/
getPublicIdentifier(): ResultAsync<PublicIdentifier, CoreUninitializedError>;
/**
* Deposit funds into Hypernet Core.
* @param assetAddress the Ethereum address of the token to deposit
* @param amount the amount of the token to deposit
*/
depositFunds(assetAddress: string, amount: BigNumber): ResultAsync<Balances, BalancesUnavailableError | CoreUninitializedError | BlockchainUnavailableError | VectorError | Error>;
/**
* Withdraw funds from Hypernet Core to a specified destination (Ethereum) address.
* @param assetAddress the address of the token to withdraw
* @param amount the amount of the token to withdraw
* @param destinationAddress the (Ethereum) address to withdraw to
*/
withdrawFunds(assetAddress: EthereumAddress, amount: BigNumber, destinationAddress: EthereumAddress): ResultAsync<Balances, BalancesUnavailableError | CoreUninitializedError | BlockchainUnavailableError | VectorError | Error>;
/**
* Returns the current balances for this instance of Hypernet Core.
*/
getBalances(): ResultAsync<Balances, BalancesUnavailableError | CoreUninitializedError>;
/**
* Return all Hypernet Links.
*/
getLinks(): ResultAsync<HypernetLink[], RouterChannelUnknownError | CoreUninitializedError | VectorError | Error>;
/**
* Return all *active* Hypernet Links.
*/
getActiveLinks(): ResultAsync<HypernetLink[], RouterChannelUnknownError | CoreUninitializedError | VectorError | Error>;
/**
* Returns all links with a specified counterparty.
* @param counterPartyAccount
*/
getLinkByCounterparty(counterPartyAccount: PublicIdentifier): Promise<HypernetLink>;
/**
* Sends funds to a counterparty.
* Internally, this is a three-step process. First, the consumer will notify the provider of the
* proposed terms of the payment (amount, required stake, and payment token). If the provider
* accepts these terms, they will create an insurance payment for the stake, and then the consumer
* finishes by creating a parameterized payment for the amount. The provider can immediately finalize
* the payment.
* @param linkId
* @param amount
* @param requiredStake the amount of stake that the provider must put up as part of the insurancepayment
* @param paymentToken
* @param merchantURL the registered URL for the merchant that will resolve any disputes.
*/
sendFunds(counterPartyAccount: PublicIdentifier, amount: string, expirationDate: number, requiredStake: string, paymentToken: EthereumAddress, merchantUrl: string): ResultAsync<Payment, RouterChannelUnknownError | CoreUninitializedError | VectorError | Error>;
/**
* Accepts the terms of a push payment, and puts up the stake/insurance transfer.
* @param paymentId
*/
acceptOffers(paymentIds: string[]): ResultAsync<Result<Payment, AcceptPaymentError>[], InsufficientBalanceError | AcceptPaymentError>;
/**
* Authorizes funds to a specified counterparty, with an amount, rate, & expiration date.
* @param counterPartyAccount the public identifier of the counterparty to authorize funds to
* @param totalAuthorized the total amount the counterparty is allowed to "pull"
* @param expirationDate the latest time in which the counterparty can pull funds
* @param requiredStake the amount of stake the counterparyt must put up as insurance
* @param paymentToken the (Ethereum) address of the payment token
* @param merchantUrl the registered URL for the merchant that will resolve any disputes.
*/
authorizeFunds(counterPartyAccount: PublicIdentifier, totalAuthorized: BigNumber, expirationDate: number, deltaAmount: string, deltaTime: number, requiredStake: BigNumber, paymentToken: EthereumAddress, merchantUrl: string): ResultAsync<Payment, RouterChannelUnknownError | CoreUninitializedError | VectorError | Error>;
/**
* Pull funds for a given payment
* @param paymentId the payment for which to pull funds from
* @param amount the amount of funds to pull
*/
pullFunds(paymentId: string, amount: BigNumber): ResultAsync<Payment, RouterChannelUnknownError | CoreUninitializedError | VectorError | Error>;
/**
* Finalize a pull-payment.
*/
finalizePullPayment(paymentId: string, finalAmount: BigNumber): Promise<HypernetLink>;
/**
* Initiate a dispute for a particular payment.
* @param paymentId the payment for which to dispute
* @param metadata the data provided to the dispute mediator about this dispute
*/
initiateDispute(paymentId: string): ResultAsync<Payment, CoreUninitializedError>;
/**
* Initialize this instance of Hypernet Core
* @param account: the ethereum account to initialize with
*/
initialize(account: string): ResultAsync<void, LogicalError>;
/**
* Mints the test token to the Ethereum address associated with the Core account.
* @param amount the amount of test token to mint
*/
mintTestToken(amount: BigNumber): ResultAsync<void, CoreUninitializedError>;
authorizeMerchant(merchantUrl: string): ResultAsync<void, CoreUninitializedError | MerchantValidationError>;
getAuthorizedMerchants(): ResultAsync<Map<string, string>, PersistenceError>;
}
//# sourceMappingURL=HypernetCore.d.ts.map