@chipi-stack/types
Version:
Type definitions for Chipi SDK packages
290 lines (282 loc) • 7.85 kB
text/typescript
import { TypedData, Call } from 'starknet';
/**
* Core configuration and environment types
*/
interface ChipiSDKConfig {
apiPublicKey: string;
environment?: "development" | "production";
nodeUrl?: string;
}
type Environment = "development" | "production";
type Chain = "STARKNET" | "STARKNET_SEPOLIA";
type ChainToken = "USDC" | "USDT" | "ETH" | "STRK" | "DAI" | "OTHER";
interface PaginationQuery {
page?: number;
limit?: number;
}
interface PaginatedResponse<T> {
data: T[];
total: number;
page: number;
limit: number;
totalPages: number;
}
declare const STARKNET_CONTRACTS: Record<ChainToken, {
contractAddress: string;
decimals: number;
}>;
/**
* Wallet-related types
*/
interface WalletData {
publicKey: string;
encryptedPrivateKey: string;
}
interface WalletDataResponse {
publicKey: string;
encryptedPrivateKey: string;
}
interface CreateWalletParams {
encryptKey: string;
externalUserId: string;
}
interface CreateWalletResponse {
txHash: string;
walletPublicKey: string;
wallet: WalletData;
}
interface GetWalletParams {
externalUserId: string;
bearerToken: string;
}
interface BackendGetWalletResponse {
id: string;
userId?: string;
orgId?: string;
apiPublicKey: string;
publicKey: string;
encryptedPrivateKey: string;
externalUserId?: string;
createdAt?: string;
updatedAt?: string;
}
interface PrepareWalletCreationParams {
encryptKey: string;
apiPublicKey: string;
}
interface PrepareWalletCreationResponse {
typeData: TypedData;
accountClassHash: string;
}
interface CreateCustodialWalletParams {
chain: Chain;
orgId: string;
}
interface GetMerchantWalletParams {
apiKeyId: string;
chain: Chain;
orgId: string;
}
/**
* Transaction-related types
*/
interface ExecuteTransactionParams {
encryptKey: string;
wallet: WalletData;
calls: Call[];
bearerToken: string;
apiPublicKey: string;
}
interface Transaction {
id: string;
chain: "STARKNET" | "BASE" | "ARBITRUM" | "OPTIMISM" | "ROOTSTOCK" | "SCROLL" | "WORLDCHAIN";
apiPublicKey: string;
transactionHash: string;
blockNumber: number;
senderAddress: string;
destinationAddress: string;
amount: string;
token: "USDC" | "USDT" | "DAI" | "ETH" | "STRK" | "SLINK" | "ALF" | "BROTHER" | "ARB" | "DOC" | "MXNB" | "WLD";
calledFunction?: string;
amountInUSD: number;
status: string;
isChipiWallet: boolean;
createdAt: Date;
updatedAt: Date;
}
interface PrepareTypedDataParams {
calls: Call[];
walletAddress: string;
}
interface ExecuteSponsoredTransactionParams {
calls: Call[];
walletAddress: string;
signature: string[];
apiPublicKey: string;
}
interface ExecuteSponsoredTransactionResponse {
transactionHash: string;
success: boolean;
}
interface RecordSendTransactionParams {
transactionHash: string;
expectedSender: string;
expectedRecipient: string;
expectedToken: ChainToken;
expectedAmount: string;
chain: Chain;
}
interface TransferParams {
encryptKey: string;
wallet: WalletData;
token: ChainToken;
otherToken?: {
contractAddress: string;
decimals: number;
};
recipient: string;
amount: string;
}
interface ApproveParams {
encryptKey: string;
wallet: WalletData;
contractAddress: string;
spender: string;
amount: string | number;
decimals?: number;
bearerToken: string;
apiPublicKey: string;
}
interface StakeVesuUsdcParams {
encryptKey: string;
wallet: WalletData;
amount: string | number;
receiverWallet: string;
bearerToken: string;
apiPublicKey: string;
}
interface WithdrawVesuUsdcParams {
encryptKey: string;
wallet: WalletData;
amount: string | number;
recipient: string;
bearerToken: string;
apiPublicKey: string;
}
interface CallAnyContractParams {
encryptKey: string;
wallet: WalletData;
contractAddress: string;
calls: Call[];
bearerToken: string;
apiPublicKey: string;
}
interface GetTransactionsParams {
page?: number;
limit?: number;
orgId: string;
}
/**
* SKU (Stock Keeping Unit) related types
*/
type SkuCategory = 'MOBILE_RECHARGE' | 'UTILITIES' | 'ENTERTAINMENT' | 'GIFT_CARDS' | 'TRANSPORTATION';
interface Sku {
id: string;
name: string;
description?: string;
category: SkuCategory;
price: number;
currency: string;
isActive: boolean;
metadata?: Record<string, any>;
createdAt: Date;
updatedAt: Date;
}
interface FindSkusParams {
categories?: SkuCategory[];
}
interface FindSkusResponse {
skus: Sku[];
}
interface CreateSkuTransactionParams {
walletAddress: string;
skuId: string;
chain: Chain;
chainToken: ChainToken;
mxnAmount: number;
reference: string;
transactionHash: string;
}
interface SkuTransaction {
id: string;
walletAddress: string;
skuId: string;
sku?: Sku;
chain: Chain;
chainToken: ChainToken;
mxnAmount: number;
reference: string;
transactionHash: string;
status: 'PENDING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';
createdAt: Date;
updatedAt: Date;
}
/**
* API-related types and interfaces
*/
interface ApiKey {
id: string;
publicKey: string;
secretKey: string;
environment: 'development' | 'production';
isActive: boolean;
orgId: string;
createdAt: Date;
updatedAt: Date;
}
interface ApiResponse<T = any> {
success: boolean;
data?: T;
error?: string;
message?: string;
}
interface ApiError {
code: string;
message: string;
details?: any;
}
interface AuthContext {
apiKey: ApiKey;
orgId: string;
userId?: string;
}
interface JwtPayload {
sub: string;
iss: string;
aud: string;
exp: number;
iat: number;
[key: string]: any;
}
/**
* Utility types and helper interfaces
*/
type Prettify<T> = {
[K in keyof T]: T[K];
} & {};
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
}[Keys];
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
type NonEmptyArray<T> = [T, ...T[]];
interface ErrorWithCode extends Error {
code?: string;
status?: number;
}
type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (...args: any) => Promise<infer R> ? R : any;
type ValueOrFunction<T> = T | (() => T);
type MaybePromise<T> = T | Promise<T>;
export { type ApiError, type ApiKey, type ApiResponse, type ApproveParams, type AsyncReturnType, type AuthContext, type BackendGetWalletResponse, type CallAnyContractParams, type Chain, type ChainToken, type ChipiSDKConfig, type CreateCustodialWalletParams, type CreateSkuTransactionParams, type CreateWalletParams, type CreateWalletResponse, type DeepPartial, type Environment, type ErrorWithCode, type ExecuteSponsoredTransactionParams, type ExecuteSponsoredTransactionResponse, type ExecuteTransactionParams, type FindSkusParams, type FindSkusResponse, type GetMerchantWalletParams, type GetTransactionsParams, type GetWalletParams, type JwtPayload, type MaybePromise, type NonEmptyArray, type Optional, type PaginatedResponse, type PaginationQuery, type PrepareTypedDataParams, type PrepareWalletCreationParams, type PrepareWalletCreationResponse, type Prettify, type RecordSendTransactionParams, type RequireAtLeastOne, STARKNET_CONTRACTS, type Sku, type SkuCategory, type SkuTransaction, type StakeVesuUsdcParams, type Transaction, type TransferParams, type ValueOrFunction, type WalletData, type WalletDataResponse, type WithdrawVesuUsdcParams };