UNPKG

hypay-adapter

Version:

Provides an XRPL payment adapter.

176 lines (169 loc) 5.15 kB
type TransactionResult = { validated: boolean; success: boolean; submitted: boolean; resolved: boolean; txid: string | null; createdAt?: string; expiresAt?: string; code?: string; message?: string; raw?: any; }; interface ErrorResponse { code: number; message: string; data?: any; } type NETWORK_TYPES = 'LOCALNET' | 'TESTNET' | 'DEVNET' | 'MAINNET'; declare namespace WalletTypes { type Name = 'GEM' | 'XAMAN' | 'GIRRIN'; interface Connection { address: string; publicKey?: string; providerName: WalletTypes.Name; } interface CreatePaymentParams { /** * Amount to send in drops (1 XRP = 1,000,000 drops) */ amount: string; /** * Optional metadata. */ meta_data?: { /** * A unique identifier for the transaction. * Useful for tracking the payment in your backend systems. */ identifier?: string; /** * A short, user-friendly instruction shown during the signing process. * Helps the user understand what they are approving. */ instruction?: string; /** * Optional structured data (e.g. memo or order details). */ blob?: Record<string, unknown>; }; } interface SignAndSubmitParams { payloadUuid: string; } interface RejectParams { id: number; reason: ErrorResponse; } interface RequestParams { method: string; params: any; } interface RespondParams { requestId: string; result?: any; error?: ErrorResponse; } interface PingParams { } interface DisconnectParams { reason: ErrorResponse; } type WalletConnectionResult = Promise<WalletTypes.Connection>; type AcknowledgedPromise = Promise<{ acknowledged: () => Promise<void>; }>; type WalletQueue<T> = { state: 'IDLE' | 'ACTIVE'; queue: T[]; }; } /** * AbstractWallet defines a unified interface for interacting with * various wallet providers such as Xaman, Gem, Girin, etc. */ declare abstract class AbstractWallet { protected networkType: NETWORK_TYPES; protected networkAddress: string; constructor(network?: NETWORK_TYPES); /** * Initialize the wallet SDK or internal state. */ abstract init(): Promise<void>; /** * Establish a connection to the wallet and return connection info. */ abstract connect(): WalletTypes.WalletConnectionResult; /** * create a payment transaction. */ abstract createPaymentTx(params: WalletTypes.CreatePaymentParams): Promise<string>; /** * Sign a payload or transaction using the connected wallet and submit a signed transaction to the XRP Ledger. */ abstract signAndSubmit(params: WalletTypes.SignAndSubmitParams): Promise<string>; /** * Check the result or status of a submitted payload. */ abstract getSubmittedTxResult(payloadUuid: string): Promise<TransactionResult>; /** * Check the result or status of a submitted transaction. */ /** * Send a general request to the wallet. */ abstract request(params: WalletTypes.RequestParams): Promise<string>; /** * Respond to a previously received request, if applicable. */ abstract respond(params: WalletTypes.RespondParams): Promise<void>; /** * Check the connection status (if supported by the provider). */ abstract ping(params?: WalletTypes.PingParams): Promise<{ pong: boolean; }>; /** * Explicitly disconnect from the wallet. */ abstract disconnect(params?: WalletTypes.DisconnectParams): Promise<void>; /** * Format a human-readable authentication message. */ abstract formatAuthMessage(params: { payload: string; origin: string; }): string; getCurrentFee(): Promise<{ medianFee: string; }>; } declare class XamanWallet$1 extends AbstractWallet { private destinationAddress; private connectedAddress; private xumm; private txidTopayloadUuidMapper; private apiKey; private apiSecret; constructor(destination: string, apiCredentials?: { key: string; secret: string; }); init(): Promise<void>; connect(): WalletTypes.WalletConnectionResult; createPaymentTx({ amount, meta_data }: WalletTypes.CreatePaymentParams): Promise<string>; signAndSubmit({ payloadUuid }: WalletTypes.SignAndSubmitParams): Promise<string>; getSubmittedTxResult(payloadUuid: string): Promise<TransactionResult>; request({ method, params }: WalletTypes.RequestParams): Promise<string>; respond(_: WalletTypes.RespondParams): Promise<void>; ping(): Promise<{ pong: boolean; }>; disconnect(): Promise<void>; formatAuthMessage(params: { payload: string; origin: string; }): string; } declare const XamanWallet: typeof XamanWallet$1; export { XamanWallet };