UNPKG

pipegate-sdk

Version:

A TypeScript client-side payment authentication SDK for stablecoins used with axios

79 lines (78 loc) 2.92 kB
import type { CreateChannelParams, CreateChannelResponse, PaymentChannelResponse, SignedRequest } from "./types"; import "dotenv/config"; import { type InternalAxiosRequestConfig } from "axios"; export declare class ClientInterceptor { private nonceMap; private channelStates; private account; constructor(); /** * Create a new payment channel * @param params CreateChannelParams - recipient, duration, tokenAddress, amount * @returns CreateChannelResponse - channelId, channelAddress, sender, recipient, duration, tokenAddress, amount, price, timestamp */ createPaymentChannel(params: CreateChannelParams): Promise<CreateChannelResponse>; /** * * @param channelId channel id * @param channelState channel state */ addNewChannel(channelId: string, channelState: CreateChannelResponse): void; /** * gets the state of a payment channel * @param channelId * @returns */ getChannelState(channelId: string): PaymentChannelResponse | undefined; private getNonce; /** * signs a request with channel details * @param paymentChannel PaymentChannelResponse * @param rawBody Body of the request * @returns SignedRequest */ signPaymentChannelRequest(paymentChannel: PaymentChannelResponse, rawBody: any): Promise<SignedRequest>; /** * signs a request with one time payment details * @param txHash Transaction Hash * @returns SignedRequest */ signOneTimePaymentRequest(txHash: `0x${string}`): Promise<SignedRequest>; /** * signs a request with stream details * @param sender Sender Address * @returns SignedRequest */ signStreamRequest(sender: `0x${string}`): Promise<SignedRequest>; /** * creates an interceptor for HTTP clients (axios, fetch) * @param channelId */ createPaymentChannelRequestInterceptor(channelId: string): { request: (config: InternalAxiosRequestConfig) => Promise<InternalAxiosRequestConfig<any>>; }; /** * creates a one time payment request interceptor for HTTP clients (axios, fetch) * @param txHash */ createOneTimePaymentRequestInterceptor(txHash: `0x${string}`): { request: (config: InternalAxiosRequestConfig) => Promise<InternalAxiosRequestConfig<any>>; }; /** * creates a stream based requests interceptor for HTTP clients (axios, fetch) * @param sender */ createStreamRequestInterceptor(sender: `0x${string}`): { request: (config: InternalAxiosRequestConfig) => Promise<InternalAxiosRequestConfig<any>>; }; /** * creates an response interceptor and extracts payment channel state */ createPaymentChannelResponseInterceptor(): { response: (response: any) => any; }; /** * helper method to extract channelId from event logs */ private getChannelIdFromLogs; }