stacks-pay
Version:
A Payment Request Standard for Stacks Blockchain Payments
74 lines (73 loc) • 2.82 kB
TypeScript
import { StacksPayParams, STXTransferParams, SIP10ContractCallParams } from "./types";
export declare class StacksPay {
private static BASE_URL;
/**
* Encode a URL into Bech32m format with HRP 'stx'
* @param url - The URL to encode
* @returns Bech32m-encoded string
*/
static encode(url: string): string;
/**
* Decode a Bech32m-encoded URL back to original form
* @param bech32mUrl - The Bech32m-encoded URL
* @returns The original URL string
*/
static decode(bech32mUrl: string): string;
/**
* Generates a unique spId using cryptographic random bytes
* @returns Base58-encoded spId
*/
static generateSpId(): string;
/**
* Validate a Stacks address format (basic validation)
* @param address - The address to validate
* @returns True if valid, else false
*/
static isValidStacksAddress(address: string): boolean;
/**
* Validate the operation type, supporting both standard and custom operations
* @param operation - The operation type to validate
* @returns True if valid, else false
*/
static isValidOperation(operation: string): boolean;
/**
* Validate a token. It must be 'STX' or a valid SIP-10 contract name.
* @param token - The token to validate
* @returns True if valid, else false
*/
static isValidToken(token: string): boolean;
/**
* Validate contract name format
* @param contractName - The contract name to validate
* @returns True if valid, else false
*/
static isValidContractName(contractName: string): boolean;
/**
* Validate STXTransferParams
* @param params - The STXTransferParams to validate
*/
static validateSTXTransferParams(params: STXTransferParams): void;
/**
* Validate SIP10ContractCallParams
* @param params - The SIP10ContractCallParams to validate
*/
static validateSIP10ContractCallParams<FArgs>(params: SIP10ContractCallParams<FArgs>): void;
/**
* Validate BaseStacksPayParams
* @param params - The BaseStacksPayParams to validate
*/
static validateBaseParams(params: StacksPayParams): void;
/**
* Generates a Bech32m-encoded Stacks Pay URL based on the provided parameters and operation type.
* @param params - The transaction parameters
* @param operation - The type of operation ('pay', 'donate', etc.)
* @returns Bech32m-encoded URL string
*/
static generate<FArgs>(params: StacksPayParams, operation: string): string;
/**
* Parses a Bech32m-encoded Stacks Pay URL and extracts the transaction parameters.
* @param bech32mUrl - The Bech32m-encoded URL
* @returns The decoded transaction parameters
*/
static parse<FArgs>(bech32mUrl: string): StacksPayParams;
}