httpay
Version:
HTTPay SDK for interacting with HTTPay smart contracts on Neutron
501 lines (485 loc) • 15.7 kB
TypeScript
import { StdFee, Coin } from '@cosmjs/amino';
import { CosmWasmClient, ExecuteResult, SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate';
/**
* This file was automatically generated by @cosmwasm/ts-codegen@1.12.1.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/
interface InstantiateMsg$1 {
fee_percentage: number;
registry_addr: string;
}
type ExecuteMsg$1 = {
lock_funds: {
auth_token: string;
expires: number;
max_fee: Uint128$1;
tool_id: string;
};
} | {
release: {
escrow_id: number;
usage_fee: Uint128$1;
};
} | {
refund_expired: {
escrow_id: number;
};
} | {
claim_fees: {
denom?: string | null;
};
};
type Uint128$1 = string;
type QueryMsg$1 = {
get_escrow: {
escrow_id: number;
};
} | {
get_collected_fees: {};
} | {
get_escrows: {
caller?: string | null;
limit?: number | null;
provider?: string | null;
start_after?: number | null;
};
};
type Addr = string;
interface CollectedFeesResponse {
collected_fees: [string, Uint128$1][];
fee_percentage: number;
owner: Addr;
}
interface EscrowResponse {
auth_token: string;
caller: Addr;
denom: string;
escrow_id: number;
expires: number;
max_fee: Uint128$1;
provider: Addr;
}
interface EscrowsResponse {
escrows: EscrowResponse[];
}
type Escrow_types_Addr = Addr;
type Escrow_types_CollectedFeesResponse = CollectedFeesResponse;
type Escrow_types_EscrowResponse = EscrowResponse;
type Escrow_types_EscrowsResponse = EscrowsResponse;
declare namespace Escrow_types {
export type { Escrow_types_Addr as Addr, Escrow_types_CollectedFeesResponse as CollectedFeesResponse, Escrow_types_EscrowResponse as EscrowResponse, Escrow_types_EscrowsResponse as EscrowsResponse, ExecuteMsg$1 as ExecuteMsg, InstantiateMsg$1 as InstantiateMsg, QueryMsg$1 as QueryMsg, Uint128$1 as Uint128 };
}
/**
* This file was automatically generated by @cosmwasm/ts-codegen@1.12.1.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/
interface EscrowReadOnlyInterface {
contractAddress: string;
getEscrow: ({ escrowId }: {
escrowId: number;
}) => Promise<EscrowResponse>;
getCollectedFees: () => Promise<CollectedFeesResponse>;
getEscrows: ({ caller, limit, provider, startAfter, }: {
caller?: string;
limit?: number;
provider?: string;
startAfter?: number;
}) => Promise<EscrowsResponse>;
}
declare class EscrowQueryClient implements EscrowReadOnlyInterface {
client: CosmWasmClient;
contractAddress: string;
constructor(client: CosmWasmClient, contractAddress: string);
getEscrow: ({ escrowId, }: {
escrowId: number;
}) => Promise<EscrowResponse>;
getCollectedFees: () => Promise<CollectedFeesResponse>;
getEscrows: ({ caller, limit, provider, startAfter, }: {
caller?: string;
limit?: number;
provider?: string;
startAfter?: number;
}) => Promise<EscrowsResponse>;
}
interface EscrowInterface extends EscrowReadOnlyInterface {
contractAddress: string;
sender: string;
lockFunds: ({ authToken, expires, maxFee, toolId, }: {
authToken: string;
expires: number;
maxFee: Uint128$1;
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
release: ({ escrowId, usageFee, }: {
escrowId: number;
usageFee: Uint128$1;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
refundExpired: ({ escrowId, }: {
escrowId: number;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
claimFees: ({ denom, }: {
denom?: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}
declare class EscrowClient extends EscrowQueryClient implements EscrowInterface {
client: SigningCosmWasmClient;
sender: string;
contractAddress: string;
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string);
lockFunds: ({ authToken, expires, maxFee, toolId, }: {
authToken: string;
expires: number;
maxFee: Uint128$1;
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
release: ({ escrowId, usageFee, }: {
escrowId: number;
usageFee: Uint128$1;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
refundExpired: ({ escrowId, }: {
escrowId: number;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
claimFees: ({ denom, }: {
denom?: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}
/**
* This file was automatically generated by @cosmwasm/ts-codegen@1.12.1.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/
interface InstantiateMsg {
}
type ExecuteMsg = {
register_tool: {
denom?: string | null;
description: string;
endpoint: string;
price: Uint128;
tool_id: string;
};
} | {
update_price: {
price: Uint128;
tool_id: string;
};
} | {
update_denom: {
denom: string;
tool_id: string;
};
} | {
update_endpoint: {
endpoint: string;
tool_id: string;
};
} | {
pause_tool: {
tool_id: string;
};
} | {
resume_tool: {
tool_id: string;
};
};
type Uint128 = string;
type QueryMsg = {
get_tool: {
tool_id: string;
};
} | {
get_tools: {};
};
interface ToolResponse {
denom: string;
description: string;
endpoint: string;
is_active: boolean;
price: Uint128;
provider: string;
tool_id: string;
}
interface ToolsResponse {
tools: ToolResponse[];
}
type Registry_types_ExecuteMsg = ExecuteMsg;
type Registry_types_InstantiateMsg = InstantiateMsg;
type Registry_types_QueryMsg = QueryMsg;
type Registry_types_ToolResponse = ToolResponse;
type Registry_types_ToolsResponse = ToolsResponse;
type Registry_types_Uint128 = Uint128;
declare namespace Registry_types {
export type { Registry_types_ExecuteMsg as ExecuteMsg, Registry_types_InstantiateMsg as InstantiateMsg, Registry_types_QueryMsg as QueryMsg, Registry_types_ToolResponse as ToolResponse, Registry_types_ToolsResponse as ToolsResponse, Registry_types_Uint128 as Uint128 };
}
/**
* This file was automatically generated by @cosmwasm/ts-codegen@1.12.1.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/
interface RegistryReadOnlyInterface {
contractAddress: string;
getTool: ({ toolId }: {
toolId: string;
}) => Promise<ToolResponse>;
getTools: () => Promise<ToolsResponse>;
}
declare class RegistryQueryClient implements RegistryReadOnlyInterface {
client: CosmWasmClient;
contractAddress: string;
constructor(client: CosmWasmClient, contractAddress: string);
getTool: ({ toolId }: {
toolId: string;
}) => Promise<ToolResponse>;
getTools: () => Promise<ToolsResponse>;
}
interface RegistryInterface extends RegistryReadOnlyInterface {
contractAddress: string;
sender: string;
registerTool: ({ denom, description, endpoint, price, toolId, }: {
denom?: string;
description: string;
endpoint: string;
price: Uint128;
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
updatePrice: ({ price, toolId, }: {
price: Uint128;
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
updateDenom: ({ denom, toolId, }: {
denom: string;
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
updateEndpoint: ({ endpoint, toolId, }: {
endpoint: string;
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
pauseTool: ({ toolId, }: {
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
resumeTool: ({ toolId, }: {
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}
declare class RegistryClient extends RegistryQueryClient implements RegistryInterface {
client: SigningCosmWasmClient;
sender: string;
contractAddress: string;
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string);
registerTool: ({ denom, description, endpoint, price, toolId, }: {
denom?: string;
description: string;
endpoint: string;
price: Uint128;
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
updatePrice: ({ price, toolId, }: {
price: Uint128;
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
updateDenom: ({ denom, toolId, }: {
denom: string;
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
updateEndpoint: ({ endpoint, toolId, }: {
endpoint: string;
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
pauseTool: ({ toolId, }: {
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
resumeTool: ({ toolId, }: {
toolId: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}
interface HTTPayConfig {
rpcEndpoint: string;
registryAddress: string;
escrowAddress: string;
chainId?: string;
gasPrice?: string;
gasAdjustment?: number;
}
interface ToolConfig {
toolId: string;
provider: {
privateKey: string;
address?: string;
};
}
interface PaymentValidationResult {
isValid: boolean;
escrow?: {
id: number;
provider: string;
maxFee: string;
expires: any;
};
error?: string;
}
interface PaymentProcessResult {
success: boolean;
txHash?: string;
fee?: string;
error?: string;
}
interface PaymentRequest {
escrowId: string | number;
authToken: string;
}
interface APIResponse<T = any> {
success: boolean;
data?: T;
escrow?: {
id: number;
provider: string;
maxFee: string;
expires: any;
};
usage?: {
timestamp: string;
fee: string;
transactionHash: string;
};
error?: string;
message?: string;
details?: any;
}
/**
* High-level HTTPay provider class that simplifies contract interactions
*/
declare class HTTPayProvider {
private config;
private tool;
private cosmWasmClient?;
private signingClient?;
private providerAddress?;
constructor(config: HTTPayConfig, tool: ToolConfig);
/**
* Initialize the provider with blockchain connections
*/
initialize(): Promise<void>;
/**
* Validate payment credentials (escrow ID and auth token)
*/
validatePayment(payment: PaymentRequest): Promise<PaymentValidationResult>;
/**
* Get tool pricing from registry
*/
getToolPrice(): Promise<{
price?: string;
error?: string;
}>;
/**
* Process payment by releasing escrow funds
*/
processPayment(escrowId: number, usageFee: string): Promise<PaymentProcessResult>;
/**
* Complete payment flow: validate + process
*/
handlePayment(payment: PaymentRequest): Promise<{
validation: PaymentValidationResult;
processing?: PaymentProcessResult;
price?: string;
}>;
/**
* Private helper to create signing client
*/
private createSigningClient;
}
/**
* Environment-based configuration utility
*/
declare class HTTPayConfigBuilder {
private config;
private tool;
/**
* Load configuration from environment variables
*/
static fromEnvironment(): HTTPayConfigBuilder;
/**
* Set RPC endpoint
*/
rpcEndpoint(endpoint: string): HTTPayConfigBuilder;
/**
* Set contract addresses
*/
contracts(registryAddress: string, escrowAddress: string): HTTPayConfigBuilder;
/**
* Set chain configuration
*/
chain(chainId: string, gasPrice?: string, gasAdjustment?: number): HTTPayConfigBuilder;
/**
* Set tool configuration
*/
setTool(toolId: string, privateKey: string): HTTPayConfigBuilder;
/**
* Build the final configuration objects
*/
build(): {
config: HTTPayConfig;
tool: ToolConfig;
};
}
/**
* Preset configurations for common networks
*/
declare const HTTPayPresets: {
readonly neutronTestnet: {
readonly rpcEndpoint: "https://rpc-falcron.pion-1.ntrn.tech";
readonly chainId: "pion-1";
readonly gasPrice: "0.0053untrn";
readonly gasAdjustment: 1.3;
readonly registryAddress: "";
readonly escrowAddress: "";
};
readonly neutronMainnet: {
readonly rpcEndpoint: "https://neutron-rpc.publicnode.com";
readonly chainId: "neutron-1";
readonly gasPrice: "0.0053untrn";
readonly gasAdjustment: 1.3;
readonly registryAddress: "";
readonly escrowAddress: "";
};
};
/**
* Quick configuration helper
*/
declare function createHTTPPayConfig(preset: keyof typeof HTTPayPresets, addresses: {
registryAddress: string;
escrowAddress: string;
}): HTTPayConfig;
/**
* Organized namespace exports for HTTPay SDK (Core only - no React dependencies)
*/
declare const Escrow: {
EscrowQueryClient: typeof EscrowQueryClient;
EscrowClient: typeof EscrowClient;
};
declare const Registry: {
RegistryQueryClient: typeof RegistryQueryClient;
RegistryClient: typeof RegistryClient;
};
declare const _default: {
Escrow: {
EscrowQueryClient: typeof EscrowQueryClient;
EscrowClient: typeof EscrowClient;
};
Registry: {
RegistryQueryClient: typeof RegistryQueryClient;
RegistryClient: typeof RegistryClient;
};
};
declare const namespace_Escrow: typeof Escrow;
declare const namespace_Registry: typeof Registry;
declare namespace namespace {
export {
namespace_Escrow as Escrow,
namespace_Registry as Registry,
_default as default,
};
}
export { EscrowClient, EscrowQueryClient, Escrow_types as EscrowTypes, namespace as HTTPay, HTTPayConfigBuilder, HTTPayPresets, HTTPayProvider, RegistryClient, RegistryQueryClient, Registry_types as RegistryTypes, createHTTPPayConfig };
export type { APIResponse, EscrowInterface, EscrowReadOnlyInterface, HTTPayConfig, PaymentProcessResult, PaymentRequest, PaymentValidationResult, RegistryInterface, RegistryReadOnlyInterface, ToolConfig };