@chipi-stack/types
Version:
Type definitions for Chipi SDK packages
304 lines (294 loc) • 8.27 kB
text/typescript
import { TypedData, Call } from 'starknet';
/**
* Core configuration and environment types
*/
interface ChipiSDKConfig {
apiPublicKey: string;
environment?: "development" | "production";
nodeUrl?: string;
apiSecretKey?: string;
}
interface ChipiServerSDKConfig extends ChipiSDKConfig {
apiSecretKey: string;
}
interface ChipiBrowserSDKConfig extends Omit<ChipiSDKConfig, 'apiSecretKey'> {
apiSecretKey?: never;
}
type Environment = "development" | "production";
type Chain = "STARKNET";
type ChainToken = "USDC" | "USDT" | "ETH" | "STRK" | "DAI" | "WBTC" | "OTHER";
interface PaginationQuery {
page?: number;
limit?: number;
offset?: 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 CreateWalletParams {
encryptKey: string;
externalUserId: string;
}
interface CreateWalletResponse {
txHash: string;
walletPublicKey: string;
wallet: WalletData & {
normalizedPublicKey: string;
};
}
interface GetWalletParams {
externalUserId: string;
}
interface GetTokenBalanceParams {
externalUserId?: string;
walletPublicKey?: string;
chainToken: ChainToken;
chain: Chain;
}
interface GetTokenBalanceResponse {
chain: Chain;
chainToken: ChainToken;
chainTokenAddress: string;
decimals: number;
balance: string;
}
interface GetWalletResponse {
id: string;
userId?: string;
orgId?: string;
publicKey: string;
encryptedPrivateKey: string;
normalizedPublicKey: 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[];
}
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;
}
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;
}
interface CallAnyContractParams {
encryptKey: string;
wallet: WalletData;
contractAddress: string;
calls: Call[];
}
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, unknown>;
createdAt: Date;
updatedAt: Date;
}
interface FindSkusParams {
categories?: SkuCategory[];
}
interface GetSkusDto extends PaginationQuery {
categories?: SkuCategory[];
}
interface GetSkusQuery extends PaginationQuery {
provider?: string;
category?: SkuCategory;
}
interface FindSkusResponse {
skus: Sku[];
}
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;
}
interface CreateSkuTransactionParams {
wallet: WalletData;
skuId: string;
mxnAmount: number;
reference: string;
encryptKey: string;
externalUserId: string;
}
interface StakeVesuUsdcParams {
encryptKey: string;
wallet: WalletData;
amount: number;
receiverWallet: string;
}
interface WithdrawVesuUsdcParams {
encryptKey: string;
wallet: WalletData;
amount: number;
recipient: string;
}
/**
* 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> {
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 CallAnyContractParams, type Chain, type ChainToken, type ChipiBrowserSDKConfig, type ChipiSDKConfig, type ChipiServerSDKConfig, 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 GetSkusDto, type GetSkusQuery, type GetTokenBalanceParams, type GetTokenBalanceResponse, type GetTransactionsParams, type GetWalletParams, type GetWalletResponse, 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 WithdrawVesuUsdcParams };