@bit-gpt/h402
Version:
BitGPT's 402 open protocol for blockchain-native payments
99 lines • 3.62 kB
TypeScript
import { Address, Hex } from "viem";
import { Network, PaymentRequirements, EvmPaymentPayload, SolanaPaymentPayload, Price, ERC20TokenAmount, RoutePattern, RoutesConfig, RouteConfig } from "../types/index.js";
/**
* Computes the route patterns for the given routes config
*
* @param routes - The routes config to compute the patterns for
* @returns The route patterns
*/
export declare function computeRoutePatterns(routes: RoutesConfig): RoutePattern[];
/**
* Finds the matching route pattern for the given path and method
*
* @param routePatterns - The route patterns to search through
* @param path - The path to match against
* @param method - The HTTP method to match against
* @returns The matching route pattern or undefined if no match is found
*/
export declare function findMatchingRoute(routePatterns: RoutePattern[], path: string, method: string): RoutePattern | undefined;
/**
* Gets the default asset (USDC/USDT) for the given network
*
* @param network - The network to get the default asset for
* @returns The default asset
*/
export declare function getDefaultAsset(network: Network): {
address: `0x${string}`;
decimals: number;
eip712: {
name: string;
version: string;
};
};
/**
* Parses the amount from the given price
*
* @param price - The price to parse
* @param network - The network to get the default asset for
* @returns The parsed amount or an error message
*/
export declare function processPriceToAtomicAmount(price: Price, network: Network): {
maxAmountRequired: string;
asset: ERC20TokenAmount["asset"];
} | {
error: string;
};
/**
* Finds the matching payment requirements for the given payment
*
* @param paymentRequirements - The payment requirements to search through
* @param payment - The payment to match against
* @returns The matching payment requirements or undefined if no match is found
*/
export declare function findMatchingPaymentRequirements(paymentRequirements: PaymentRequirements[], payment: EvmPaymentPayload | SolanaPaymentPayload): {
scheme: "exact";
namespace: "solana" | "evm";
tokenAddress: string;
amountRequired: number | bigint;
amountRequiredFormat: "humanReadable" | "smallestUnit";
payToAddress: string;
networkId: string;
description?: string | undefined;
tokenSymbol?: string | undefined;
tokenDecimals?: number | undefined;
resource?: string | undefined;
mimeType?: string | undefined;
outputSchema?: any;
estimatedProcessingTime?: number | undefined;
extra?: any;
maxAmountRequired?: number | bigint | undefined;
requiredDeadlineSeconds?: number | undefined;
} | undefined;
/**
* Decodes the X-PAYMENT-RESPONSE header
*
* @param header - The X-PAYMENT-RESPONSE header to decode
* @returns The decoded payment response
*/
export declare function decodeXPaymentResponse(header: string): {
success: boolean;
transaction: Hex;
network: Network;
payer: Address;
};
/**
* Creates a RouteConfig from a price and network
*
* @param price - The price to create the RouteConfig from
* @param network - The network to create the RouteConfig for
* @returns The created RouteConfig
*/
export declare function createRouteConfigFromPrice(price: Price, network: Network): RouteConfig;
/**
* Gets the USDC/USDT address for a given chain ID
*
* @param chainId - The chain ID (for EVM networks) or network identifier
* @returns The stablecoin token address for the chain
*/
export declare function getUsdcAddressForChain(chainId: number | string): string;
//# sourceMappingURL=middleware.d.ts.map