kryptoexpress-sdk 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +165 -0
- package/dist/index.cjs +702 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +248 -0
- package/dist/index.d.ts +248 -0
- package/dist/index.js +653 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/core/config.ts","../src/domain/errors.ts","../src/core/http.ts","../src/domain/enums.ts","../src/domain/conversion.ts","../src/core/validation.ts","../src/resources/currencies.ts","../src/resources/fiat.ts","../src/resources/payments.ts","../src/resources/wallet.ts","../src/client.ts","../src/webhooks/signature.ts"],"sourcesContent":["export * from './client';\nexport * from './domain/enums';\nexport * from './domain/errors';\nexport * from './domain/models';\nexport * from './domain/conversion';\nexport * from './webhooks/signature';\n","import type { FiatConverter } from '../domain/conversion';\n\nexport interface RetryOptions {\n maxRetries?: number;\n retryStatusCodes?: number[];\n}\n\nexport interface KryptoExpressClientOptions {\n apiKey?: string | undefined;\n baseUrl?: string | undefined;\n timeoutMs?: number | undefined;\n retry?: RetryOptions | undefined;\n fetch?: typeof fetch | undefined;\n fiatConverter?: FiatConverter | undefined;\n}\n\nexport interface ResolvedClientOptions {\n apiKey: string | undefined;\n baseUrl: string;\n timeoutMs: number;\n retry: {\n maxRetries: number;\n retryStatusCodes: number[];\n };\n fetch: typeof fetch;\n fiatConverter: FiatConverter | undefined;\n}\n\nconst DEFAULT_RETRY_STATUS_CODES = [408, 409, 429, 500, 502, 503, 504];\n\nexport function resolveClientOptions(options: KryptoExpressClientOptions = {}): ResolvedClientOptions {\n const normalizedBaseUrl = (options.baseUrl ?? 'https://kryptoexpress.pro/api').replace(/\\/+$/, '');\n\n return {\n apiKey: options.apiKey,\n baseUrl: normalizedBaseUrl,\n timeoutMs: options.timeoutMs ?? 10_000,\n retry: {\n maxRetries: options.retry?.maxRetries ?? 2,\n retryStatusCodes: options.retry?.retryStatusCodes ?? DEFAULT_RETRY_STATUS_CODES,\n },\n fetch: options.fetch ?? globalThis.fetch,\n fiatConverter: options.fiatConverter,\n };\n}\n","export interface ErrorOptions {\n cause?: unknown;\n statusCode?: number;\n code?: string;\n details?: unknown;\n}\n\nexport class SDKError extends Error {\n public readonly cause: unknown;\n\n public constructor(message: string, options: ErrorOptions = {}) {\n super(message);\n this.name = new.target.name;\n this.cause = options.cause;\n }\n}\n\nexport class ValidationError extends SDKError {\n public readonly details: unknown;\n\n public constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n this.details = options.details;\n }\n}\n\nexport class UnsupportedPaymentModeError extends ValidationError {}\n\nexport class MinimumAmountError extends ValidationError {\n public readonly minimumUsdAmount: number;\n\n public constructor(message: string, minimumUsdAmount = 1, options: ErrorOptions = {}) {\n super(message, options);\n this.minimumUsdAmount = minimumUsdAmount;\n }\n}\n\nexport class CurrencyConversionError extends ValidationError {}\n\nexport class APIError extends SDKError {\n public readonly statusCode: number;\n public readonly code: string | undefined;\n public readonly details: unknown;\n\n public constructor(message: string, statusCode: number, options: ErrorOptions = {}) {\n super(message, options);\n this.statusCode = statusCode;\n this.code = options.code;\n this.details = options.details;\n }\n}\n\nexport class AuthError extends APIError {}\nexport class RateLimitError extends APIError {}\nexport class NotFoundError extends APIError {}\n","import { APIError, AuthError, NotFoundError, RateLimitError, SDKError } from '../domain/errors';\nimport type { ResolvedClientOptions } from './config';\n\nexport interface RequestOptions {\n path: string;\n method?: 'GET' | 'POST';\n query?: Record<string, string | number | boolean | undefined>;\n body?: unknown;\n requiresAuth?: boolean;\n}\n\nexport class HttpClient {\n private readonly options: ResolvedClientOptions;\n\n public constructor(options: ResolvedClientOptions) {\n this.options = options;\n }\n\n public async request<T>(request: RequestOptions): Promise<T> {\n const url = buildUrl(this.options.baseUrl, request.path, request.query);\n\n for (let attempt = 0; ; attempt += 1) {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), this.options.timeoutMs);\n\n try {\n const requestInit: RequestInit = {\n method: request.method ?? 'GET',\n headers: this.buildHeaders(request.requiresAuth ?? false, request.body !== undefined),\n signal: controller.signal,\n };\n\n if (request.body !== undefined) {\n requestInit.body = JSON.stringify(request.body);\n }\n\n const response = await this.options.fetch(url, requestInit);\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n if (\n attempt < this.options.retry.maxRetries &&\n this.options.retry.retryStatusCodes.includes(response.status)\n ) {\n continue;\n }\n\n throw await toApiError(response);\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n return (await response.json()) as T;\n } catch (error) {\n clearTimeout(timeout);\n\n if (\n !(error instanceof APIError) &&\n attempt < this.options.retry.maxRetries\n ) {\n continue;\n }\n\n if (error instanceof Error && error.name === 'AbortError') {\n throw new SDKError(`Request timed out after ${this.options.timeoutMs}ms.`, { cause: error });\n }\n\n if (error instanceof SDKError) {\n throw error;\n }\n\n throw new SDKError('Unexpected HTTP client error.', { cause: error });\n }\n }\n }\n\n private buildHeaders(requiresAuth: boolean, hasJsonBody: boolean): Headers {\n const headers = new Headers();\n headers.set('Accept', 'application/json');\n\n if (hasJsonBody) {\n headers.set('Content-Type', 'application/json');\n }\n\n if (requiresAuth) {\n if (!this.options.apiKey) {\n throw new AuthError('This endpoint requires an API key.', 401);\n }\n\n headers.set('X-Api-Key', this.options.apiKey);\n }\n\n return headers;\n }\n}\n\nfunction buildUrl(\n baseUrl: string,\n path: string,\n query: Record<string, string | number | boolean | undefined> = {},\n): string {\n const url = new URL(`${baseUrl}${path}`);\n\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined) {\n continue;\n }\n\n url.searchParams.set(key, String(value));\n }\n\n return url.toString();\n}\n\nasync function toApiError(response: Response): Promise<APIError> {\n const bodyText = await response.text();\n let payload: Record<string, unknown> | undefined;\n\n try {\n payload = bodyText ? (JSON.parse(bodyText) as Record<string, unknown>) : undefined;\n } catch {\n payload = undefined;\n }\n\n const message =\n (typeof payload?.message === 'string' && payload.message) ||\n (typeof payload?.error === 'string' && payload.error) ||\n `Request failed with status ${response.status}.`;\n const code = typeof payload?.code === 'string' ? payload.code : undefined;\n const options =\n code === undefined\n ? { details: payload ?? bodyText }\n : { code, details: payload ?? bodyText };\n\n if (response.status === 401 || response.status === 403) {\n return new AuthError(message, response.status, options);\n }\n\n if (response.status === 404) {\n return new NotFoundError(message, response.status, options);\n }\n\n if (response.status === 429) {\n return new RateLimitError(message, response.status, options);\n }\n\n return new APIError(message, response.status, options);\n}\n","export const FIAT_CURRENCIES = [\n 'USD',\n 'EUR',\n 'GBP',\n 'JPY',\n 'CHF',\n 'AUD',\n 'CAD',\n 'CNY',\n 'HKD',\n 'SGD',\n 'SEK',\n 'NOK',\n 'DKK',\n 'PLN',\n 'CZK',\n 'HUF',\n 'TRY',\n 'INR',\n 'KRW',\n 'THB',\n 'IDR',\n 'MYR',\n 'PHP',\n 'VND',\n 'AED',\n 'SAR',\n 'ZAR',\n 'NGN',\n 'KES',\n 'GHS',\n 'BRL',\n 'MXN',\n 'ARS',\n 'CLP',\n 'COP',\n 'PEN',\n 'RUB',\n 'UAH',\n 'ILS',\n 'PKR',\n 'BDT',\n 'LKR',\n 'TWD',\n 'BHD',\n 'KWD',\n 'RON',\n 'NZD',\n] as const;\n\nexport const NATIVE_CRYPTO_CURRENCIES = ['BTC', 'LTC', 'ETH', 'SOL', 'BNB', 'DOGE'] as const;\n\nexport const STABLE_CRYPTO_CURRENCIES = [\n 'USDC_ERC20',\n 'USDT_ERC20',\n 'USDT_BEP20',\n 'USDC_BEP20',\n 'USDT_SOL',\n 'USDC_SOL',\n] as const;\n\nexport const ALL_CRYPTO_CURRENCIES = [\n ...NATIVE_CRYPTO_CURRENCIES,\n ...STABLE_CRYPTO_CURRENCIES,\n] as const;\n\nexport const PAYMENT_TYPES = ['PAYMENT', 'DEPOSIT'] as const;\nexport const WITHDRAW_TYPES = ['ALL', 'SINGLE'] as const;\n\nexport type FiatCurrency = (typeof FIAT_CURRENCIES)[number];\nexport type NativeCryptoCurrency = (typeof NATIVE_CRYPTO_CURRENCIES)[number];\nexport type StableCryptoCurrency = (typeof STABLE_CRYPTO_CURRENCIES)[number];\nexport type CryptoCurrency = (typeof ALL_CRYPTO_CURRENCIES)[number];\nexport type PaymentType = (typeof PAYMENT_TYPES)[number];\nexport type WithdrawType = (typeof WITHDRAW_TYPES)[number];\n\nconst stableCurrencySet = new Set<string>(STABLE_CRYPTO_CURRENCIES);\n\nexport function isStableCryptoCurrency(value: string): value is StableCryptoCurrency {\n return stableCurrencySet.has(value);\n}\n","import {\n CurrencyConversionError,\n MinimumAmountError,\n UnsupportedPaymentModeError,\n} from './errors';\nimport { isStableCryptoCurrency, type CryptoCurrency, type FiatCurrency } from './enums';\n\nexport interface FiatConversionQuote {\n from: FiatCurrency;\n to: FiatCurrency;\n rate: number;\n}\n\nexport interface FiatConverter {\n convert(amount: number, from: FiatCurrency, to: FiatCurrency): Promise<number>;\n}\n\nexport class StaticRateFiatConverter implements FiatConverter {\n private readonly rates = new Map<string, number>();\n\n public constructor(quotes: FiatConversionQuote[]) {\n for (const quote of quotes) {\n this.rates.set(`${quote.from}:${quote.to}`, quote.rate);\n }\n }\n\n public convert(amount: number, from: FiatCurrency, to: FiatCurrency): Promise<number> {\n if (from === to) {\n return Promise.resolve(amount);\n }\n\n const direct = this.rates.get(`${from}:${to}`);\n if (direct !== undefined) {\n return Promise.resolve(amount * direct);\n }\n\n const inverse = this.rates.get(`${to}:${from}`);\n if (inverse !== undefined && inverse !== 0) {\n return Promise.resolve(amount / inverse);\n }\n\n throw new CurrencyConversionError(`No fiat conversion rate available for ${from} -> ${to}.`);\n }\n}\n\nexport interface MinimumAmountValidatorOptions {\n converter?: FiatConverter | undefined;\n minimumUsdAmount?: number | undefined;\n}\n\nexport class MinimumAmountPolicy {\n private readonly converter: FiatConverter | undefined;\n private readonly minimumUsdAmount: number;\n\n public constructor(options: MinimumAmountValidatorOptions = {}) {\n this.converter = options.converter;\n this.minimumUsdAmount = options.minimumUsdAmount ?? 1;\n }\n\n public async assertFiatAmountEligible(amount: number, fiatCurrency: FiatCurrency): Promise<void> {\n if (amount <= 0) {\n throw new MinimumAmountError('Payment amount must be greater than zero.', this.minimumUsdAmount);\n }\n\n if (fiatCurrency !== 'USD') {\n return;\n }\n\n const amountInUsd = amount;\n\n if (amountInUsd < this.minimumUsdAmount) {\n throw new MinimumAmountError(\n `Payment amount must be at least the fiat equivalent of ${this.minimumUsdAmount} USD.`,\n this.minimumUsdAmount,\n { details: { amount, fiatCurrency, amountInUsd } },\n );\n }\n }\n}\n\nexport function assertPaymentModeSupported(\n paymentType: 'PAYMENT' | 'DEPOSIT',\n cryptoCurrency: CryptoCurrency,\n): void {\n if (paymentType === 'DEPOSIT' && isStableCryptoCurrency(cryptoCurrency)) {\n throw new UnsupportedPaymentModeError(\n `Stablecoin ${cryptoCurrency} is not supported for DEPOSIT payments.`,\n );\n }\n}\n","import { ValidationError } from '../domain/errors';\nimport type { PaymentRecord, WithdrawalResponse, CryptoPrice, WalletBalances } from '../domain/models';\nimport { PAYMENT_TYPES, WITHDRAW_TYPES } from '../domain/enums';\n\nfunction assertObject(value: unknown, label: string): Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new ValidationError(`${label} must be an object.`, { details: value });\n }\n\n return value as Record<string, unknown>;\n}\n\nfunction assertString(value: unknown, label: string): string {\n if (typeof value !== 'string') {\n throw new ValidationError(`${label} must be a string.`, { details: value });\n }\n\n return value;\n}\n\nfunction assertNumberOrNull(value: unknown, label: string): number | null {\n if (value === null) {\n return null;\n }\n\n if (typeof value !== 'number' || Number.isNaN(value)) {\n throw new ValidationError(`${label} must be a number or null.`, { details: value });\n }\n\n return value;\n}\n\nfunction assertNumber(value: unknown, label: string): number {\n if (typeof value !== 'number' || Number.isNaN(value)) {\n throw new ValidationError(`${label} must be a number.`, { details: value });\n }\n\n return value;\n}\n\nfunction assertBoolean(value: unknown, label: string): boolean {\n if (typeof value !== 'boolean') {\n throw new ValidationError(`${label} must be a boolean.`, { details: value });\n }\n\n return value;\n}\n\nexport function parsePaymentRecord(value: unknown): PaymentRecord {\n const record = assertObject(value, 'payment');\n const paymentType = assertString(record.paymentType, 'payment.paymentType');\n\n if (!PAYMENT_TYPES.includes(paymentType as (typeof PAYMENT_TYPES)[number])) {\n throw new ValidationError('payment.paymentType is invalid.', { details: paymentType });\n }\n\n return {\n id: assertNumber(record.id, 'payment.id'),\n paymentType: paymentType as PaymentRecord['paymentType'],\n fiatCurrency: assertString(record.fiatCurrency, 'payment.fiatCurrency') as PaymentRecord['fiatCurrency'],\n fiatAmount: assertNumberOrNull(record.fiatAmount, 'payment.fiatAmount'),\n cryptoAmount: assertNumberOrNull(record.cryptoAmount, 'payment.cryptoAmount'),\n cryptoCurrency: assertString(\n record.cryptoCurrency,\n 'payment.cryptoCurrency',\n ) as PaymentRecord['cryptoCurrency'],\n expireDatetime: assertNumber(record.expireDatetime, 'payment.expireDatetime'),\n createDatetime: assertNumber(record.createDatetime, 'payment.createDatetime'),\n paidAt: assertNumberOrNull(record.paidAt, 'payment.paidAt'),\n address: assertString(record.address, 'payment.address'),\n isPaid: assertBoolean(record.isPaid, 'payment.isPaid'),\n isWithdrawn: assertBoolean(record.isWithdrawn, 'payment.isWithdrawn'),\n hash: assertString(record.hash, 'payment.hash'),\n callbackUrl:\n record.callbackUrl === null ? null : assertString(record.callbackUrl, 'payment.callbackUrl'),\n };\n}\n\nexport function parseWalletBalances(value: unknown): WalletBalances {\n const record = assertObject(value, 'wallet');\n const result: WalletBalances = {};\n\n for (const [currency, amount] of Object.entries(record)) {\n result[currency] = assertNumber(amount, `wallet.${currency}`);\n }\n\n return result;\n}\n\nexport function parseWithdrawalResponse(value: unknown): WithdrawalResponse {\n const record = assertObject(value, 'withdrawal');\n const withdrawType = assertString(record.withdrawType, 'withdrawal.withdrawType');\n\n if (!WITHDRAW_TYPES.includes(withdrawType as (typeof WITHDRAW_TYPES)[number])) {\n throw new ValidationError('withdrawal.withdrawType is invalid.', { details: withdrawType });\n }\n\n const txIdList = record.txIdList;\n if (!Array.isArray(txIdList) || txIdList.some((item) => typeof item !== 'string')) {\n throw new ValidationError('withdrawal.txIdList must be a string array.', { details: txIdList });\n }\n\n return {\n id: assertNumber(record.id, 'withdrawal.id'),\n withdrawType: withdrawType as WithdrawalResponse['withdrawType'],\n paymentId:\n record.paymentId === null ? null : assertNumber(record.paymentId, 'withdrawal.paymentId'),\n cryptoCurrency: assertString(\n record.cryptoCurrency,\n 'withdrawal.cryptoCurrency',\n ) as WithdrawalResponse['cryptoCurrency'],\n toAddress: assertString(record.toAddress, 'withdrawal.toAddress'),\n txIdList: txIdList as string[],\n receivingAmount: assertNumber(record.receivingAmount, 'withdrawal.receivingAmount'),\n blockchainFeeAmount: assertNumber(\n record.blockchainFeeAmount,\n 'withdrawal.blockchainFeeAmount',\n ),\n serviceFeeAmount: assertNumber(record.serviceFeeAmount, 'withdrawal.serviceFeeAmount'),\n onlyCalculate: assertBoolean(record.onlyCalculate, 'withdrawal.onlyCalculate'),\n totalWithdrawalAmount: assertNumber(\n record.totalWithdrawalAmount,\n 'withdrawal.totalWithdrawalAmount',\n ),\n createDatetime: assertNumber(record.createDatetime, 'withdrawal.createDatetime'),\n };\n}\n\nexport function parseStringArray(value: unknown, label: string): string[] {\n if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) {\n throw new ValidationError(`${label} must be a string array.`, { details: value });\n }\n\n return value as string[];\n}\n\nexport function parseCryptoPrices(value: unknown): CryptoPrice[] {\n if (!Array.isArray(value)) {\n throw new ValidationError('prices must be an array.', { details: value });\n }\n\n const items = value as unknown[];\n\n return items.map((item, index): CryptoPrice => {\n const record = assertObject(item, `prices[${index}]`);\n return {\n cryptoCurrency: assertString(record.cryptoCurrency, `prices[${index}].cryptoCurrency`) as CryptoPrice['cryptoCurrency'],\n fiatCurrency: assertString(record.fiatCurrency, `prices[${index}].fiatCurrency`) as CryptoPrice['fiatCurrency'],\n price: assertNumber(record.price, `prices[${index}].price`),\n };\n });\n}\n","import type { HttpClient } from '../core/http';\nimport { parseCryptoPrices, parseStringArray } from '../core/validation';\nimport { ValidationError } from '../domain/errors';\nimport type { CryptoCurrency, FiatCurrency, NativeCryptoCurrency, StableCryptoCurrency } from '../domain/enums';\nimport type { CryptoPrice } from '../domain/models';\n\nexport interface GetPricesInput {\n cryptoCurrency: CryptoCurrency[];\n fiatCurrency: FiatCurrency;\n}\n\nexport class CurrenciesResource {\n private readonly httpClient: HttpClient;\n\n public constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n }\n\n public async listNative(): Promise<NativeCryptoCurrency[]> {\n const response = await this.httpClient.request<unknown>({\n path: '/cryptocurrency',\n });\n\n return parseStringArray(response, 'cryptocurrency') as NativeCryptoCurrency[];\n }\n\n public async listAll(): Promise<CryptoCurrency[]> {\n const response = await this.httpClient.request<unknown>({\n path: '/cryptocurrency/all',\n });\n\n return parseStringArray(response, 'cryptocurrency/all') as CryptoCurrency[];\n }\n\n public async listStable(): Promise<StableCryptoCurrency[]> {\n const response = await this.httpClient.request<unknown>({\n path: '/cryptocurrency/stable',\n });\n\n return parseStringArray(response, 'cryptocurrency/stable') as StableCryptoCurrency[];\n }\n\n public async getPrices(input: GetPricesInput): Promise<CryptoPrice[]> {\n if (input.cryptoCurrency.length === 0) {\n throw new ValidationError('At least one cryptoCurrency is required.', { details: input });\n }\n\n const response = await this.httpClient.request<unknown>({\n path: '/cryptocurrency/price',\n query: {\n cryptoCurrency: input.cryptoCurrency.join(','),\n fiatCurrency: input.fiatCurrency,\n },\n });\n\n return parseCryptoPrices(response);\n }\n}\n","import type { HttpClient } from '../core/http';\nimport { parseStringArray } from '../core/validation';\nimport type { FiatCurrency } from '../domain/enums';\n\nexport class FiatResource {\n private readonly httpClient: HttpClient;\n\n public constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n }\n\n public async list(): Promise<FiatCurrency[]> {\n const response = await this.httpClient.request<unknown>({\n path: '/currency',\n });\n\n return parseStringArray(response, 'currency') as FiatCurrency[];\n }\n}\n","import type { HttpClient } from '../core/http';\nimport { parsePaymentRecord } from '../core/validation';\nimport { MinimumAmountPolicy, assertPaymentModeSupported } from '../domain/conversion';\nimport { UnsupportedPaymentModeError, ValidationError } from '../domain/errors';\nimport type {\n CreateDepositInput,\n CreateDepositRequest,\n CreatePaymentInput,\n CreatePaymentOrDepositRequest,\n CreatePaymentRequest,\n PaymentRecord,\n} from '../domain/models';\nimport { isStableCryptoCurrency } from '../domain/enums';\n\nexport class PaymentsResource {\n private readonly httpClient: HttpClient;\n private readonly minimumAmountPolicy: MinimumAmountPolicy;\n\n public constructor(httpClient: HttpClient, minimumAmountPolicy: MinimumAmountPolicy) {\n this.httpClient = httpClient;\n this.minimumAmountPolicy = minimumAmountPolicy;\n }\n\n public async create(input: CreatePaymentOrDepositRequest): Promise<PaymentRecord> {\n if (input.paymentType === 'PAYMENT') {\n return this.createPayment(input);\n }\n\n return this.createDeposit(input);\n }\n\n public async createPayment(input: CreatePaymentInput | CreatePaymentRequest): Promise<PaymentRecord> {\n const request: CreatePaymentRequest = {\n ...input,\n paymentType: 'PAYMENT',\n };\n\n if (request.fiatAmount <= 0) {\n throw new ValidationError('fiatAmount must be greater than zero.', { details: request });\n }\n\n assertPaymentModeSupported(request.paymentType, request.cryptoCurrency);\n await this.minimumAmountPolicy.assertFiatAmountEligible(request.fiatAmount, request.fiatCurrency);\n\n const response = await this.httpClient.request<unknown>({\n path: '/payment',\n method: 'POST',\n body: request,\n requiresAuth: true,\n });\n\n return parsePaymentRecord(response);\n }\n\n public async createDeposit(input: CreateDepositInput | CreateDepositRequest): Promise<PaymentRecord> {\n const request: CreateDepositRequest = {\n ...input,\n paymentType: 'DEPOSIT',\n };\n\n if (isStableCryptoCurrency(request.cryptoCurrency)) {\n throw new UnsupportedPaymentModeError(\n `Stablecoin ${request.cryptoCurrency} supports only PAYMENT, not DEPOSIT.`,\n { details: request },\n );\n }\n\n const response = await this.httpClient.request<unknown>({\n path: '/payment',\n method: 'POST',\n body: request,\n requiresAuth: true,\n });\n\n return parsePaymentRecord(response);\n }\n\n public async getByHash(hash: string): Promise<PaymentRecord> {\n if (!hash) {\n throw new ValidationError('hash is required.');\n }\n\n const response = await this.httpClient.request<unknown>({\n path: '/payment',\n query: { hash },\n requiresAuth: false,\n });\n\n return parsePaymentRecord(response);\n }\n}\n","import type { HttpClient } from '../core/http';\nimport { parseWalletBalances, parseWithdrawalResponse } from '../core/validation';\nimport { ValidationError } from '../domain/errors';\nimport type {\n WalletBalances,\n WithdrawalResponse,\n WithdrawAllInput,\n WithdrawSingleInput,\n} from '../domain/models';\n\nexport class WalletResource {\n private readonly httpClient: HttpClient;\n\n public constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n }\n\n public async get(): Promise<WalletBalances> {\n const response = await this.httpClient.request<unknown>({\n path: '/wallet',\n requiresAuth: true,\n });\n\n return parseWalletBalances(response);\n }\n\n public async withdraw(input: WithdrawAllInput | WithdrawSingleInput): Promise<WithdrawalResponse> {\n this.assertWithdrawalInput(input);\n\n const response = await this.httpClient.request<unknown>({\n path: '/wallet/withdrawal',\n method: 'POST',\n body: input,\n requiresAuth: true,\n });\n\n return parseWithdrawalResponse(response);\n }\n\n public async calculate(input: WithdrawAllInput | WithdrawSingleInput): Promise<WithdrawalResponse> {\n return this.withdraw({\n ...input,\n onlyCalculate: true,\n });\n }\n\n public async withdrawAll(\n input: Omit<WithdrawAllInput, 'withdrawType' | 'onlyCalculate'>,\n ): Promise<WithdrawalResponse> {\n return this.withdraw({\n ...input,\n withdrawType: 'ALL',\n onlyCalculate: false,\n });\n }\n\n public async withdrawSingle(\n input: Omit<WithdrawSingleInput, 'withdrawType' | 'onlyCalculate'>,\n ): Promise<WithdrawalResponse> {\n return this.withdraw({\n ...input,\n withdrawType: 'SINGLE',\n onlyCalculate: false,\n });\n }\n\n public async calculateAll(\n input: Omit<WithdrawAllInput, 'withdrawType' | 'onlyCalculate'>,\n ): Promise<WithdrawalResponse> {\n return this.calculate({\n ...input,\n withdrawType: 'ALL',\n });\n }\n\n public async calculateSingle(\n input: Omit<WithdrawSingleInput, 'withdrawType' | 'onlyCalculate'>,\n ): Promise<WithdrawalResponse> {\n return this.calculate({\n ...input,\n withdrawType: 'SINGLE',\n });\n }\n\n private assertWithdrawalInput(input: WithdrawAllInput | WithdrawSingleInput): void {\n if (!input.toAddress) {\n throw new ValidationError('toAddress is required.', { details: input });\n }\n\n if (input.withdrawType === 'SINGLE' && typeof input.paymentId !== 'number') {\n throw new ValidationError('paymentId is required for SINGLE withdrawals.', {\n details: input,\n });\n }\n }\n}\n","import { resolveClientOptions, type KryptoExpressClientOptions } from './core/config';\nimport { HttpClient } from './core/http';\nimport { MinimumAmountPolicy } from './domain/conversion';\nimport { CurrenciesResource } from './resources/currencies';\nimport { FiatResource } from './resources/fiat';\nimport { PaymentsResource } from './resources/payments';\nimport { WalletResource } from './resources/wallet';\n\nexport class KryptoExpressClient {\n public readonly payments: PaymentsResource;\n public readonly wallet: WalletResource;\n public readonly currencies: CurrenciesResource;\n public readonly fiat: FiatResource;\n\n public constructor(options: KryptoExpressClientOptions = {}) {\n const resolved = resolveClientOptions(options);\n const httpClient = new HttpClient(resolved);\n const minimumAmountPolicy = resolved.fiatConverter\n ? new MinimumAmountPolicy({ converter: resolved.fiatConverter })\n : new MinimumAmountPolicy();\n\n this.payments = new PaymentsResource(httpClient, minimumAmountPolicy);\n this.wallet = new WalletResource(httpClient);\n this.currencies = new CurrenciesResource(httpClient);\n this.fiat = new FiatResource(httpClient);\n }\n}\n\nexport type { KryptoExpressClientOptions } from './core/config';\n","import { createHmac, timingSafeEqual } from 'node:crypto';\n\nexport interface VerifyCallbackSignatureInput {\n rawBody: string;\n callbackSecret: string;\n signature: string | null | undefined;\n}\n\nexport function compactJson(rawBody: string): string {\n return JSON.stringify(JSON.parse(rawBody));\n}\n\nexport function computeCallbackSignature(rawBody: string, callbackSecret: string): string {\n const compactBody = compactJson(rawBody);\n return createHmac('sha512', callbackSecret).update(compactBody).digest('hex');\n}\n\nexport function verifyCallbackSignature(input: VerifyCallbackSignatureInput): boolean {\n if (!input.signature) {\n return false;\n }\n\n const expectedSignature = computeCallbackSignature(input.rawBody, input.callbackSecret);\n const actual = Buffer.from(input.signature, 'hex');\n const expected = Buffer.from(expectedSignature, 'hex');\n\n if (actual.length !== expected.length) {\n return false;\n }\n\n return timingSafeEqual(actual, expected);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BA,IAAM,6BAA6B,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAE9D,SAAS,qBAAqB,UAAsC,CAAC,GAA0B;AACpG,QAAM,qBAAqB,QAAQ,WAAW,iCAAiC,QAAQ,QAAQ,EAAE;AAEjG,SAAO;AAAA,IACL,QAAQ,QAAQ;AAAA,IAChB,SAAS;AAAA,IACT,WAAW,QAAQ,aAAa;AAAA,IAChC,OAAO;AAAA,MACL,YAAY,QAAQ,OAAO,cAAc;AAAA,MACzC,kBAAkB,QAAQ,OAAO,oBAAoB;AAAA,IACvD;AAAA,IACA,OAAO,QAAQ,SAAS,WAAW;AAAA,IACnC,eAAe,QAAQ;AAAA,EACzB;AACF;;;ACrCO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClB;AAAA,EAET,YAAY,SAAiB,UAAwB,CAAC,GAAG;AAC9D,UAAM,OAAO;AACb,SAAK,OAAO,WAAW;AACvB,SAAK,QAAQ,QAAQ;AAAA,EACvB;AACF;AAEO,IAAM,kBAAN,cAA8B,SAAS;AAAA,EAC5B;AAAA,EAET,YAAY,SAAiB,UAA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GD", "SEK", "NOK", "DKK", "PLN", "CZK", "HUF", "TRY", "INR", "KRW", "THB", "IDR", "MYR", "PHP", "VND", "AED", "SAR", "ZAR", "NGN", "KES", "GHS", "BRL", "MXN", "ARS", "CLP", "COP", "PEN", "RUB", "UAH", "ILS", "PKR", "BDT", "LKR", "TWD", "BHD", "KWD", "RON", "NZD"];
|
|
2
|
+
declare const NATIVE_CRYPTO_CURRENCIES: readonly ["BTC", "LTC", "ETH", "SOL", "BNB", "DOGE"];
|
|
3
|
+
declare const STABLE_CRYPTO_CURRENCIES: readonly ["USDC_ERC20", "USDT_ERC20", "USDT_BEP20", "USDC_BEP20", "USDT_SOL", "USDC_SOL"];
|
|
4
|
+
declare const ALL_CRYPTO_CURRENCIES: readonly ["BTC", "LTC", "ETH", "SOL", "BNB", "DOGE", "USDC_ERC20", "USDT_ERC20", "USDT_BEP20", "USDC_BEP20", "USDT_SOL", "USDC_SOL"];
|
|
5
|
+
declare const PAYMENT_TYPES: readonly ["PAYMENT", "DEPOSIT"];
|
|
6
|
+
declare const WITHDRAW_TYPES: readonly ["ALL", "SINGLE"];
|
|
7
|
+
type FiatCurrency = (typeof FIAT_CURRENCIES)[number];
|
|
8
|
+
type NativeCryptoCurrency = (typeof NATIVE_CRYPTO_CURRENCIES)[number];
|
|
9
|
+
type StableCryptoCurrency = (typeof STABLE_CRYPTO_CURRENCIES)[number];
|
|
10
|
+
type CryptoCurrency = (typeof ALL_CRYPTO_CURRENCIES)[number];
|
|
11
|
+
type PaymentType = (typeof PAYMENT_TYPES)[number];
|
|
12
|
+
type WithdrawType = (typeof WITHDRAW_TYPES)[number];
|
|
13
|
+
declare function isStableCryptoCurrency(value: string): value is StableCryptoCurrency;
|
|
14
|
+
|
|
15
|
+
interface FiatConversionQuote {
|
|
16
|
+
from: FiatCurrency;
|
|
17
|
+
to: FiatCurrency;
|
|
18
|
+
rate: number;
|
|
19
|
+
}
|
|
20
|
+
interface FiatConverter {
|
|
21
|
+
convert(amount: number, from: FiatCurrency, to: FiatCurrency): Promise<number>;
|
|
22
|
+
}
|
|
23
|
+
declare class StaticRateFiatConverter implements FiatConverter {
|
|
24
|
+
private readonly rates;
|
|
25
|
+
constructor(quotes: FiatConversionQuote[]);
|
|
26
|
+
convert(amount: number, from: FiatCurrency, to: FiatCurrency): Promise<number>;
|
|
27
|
+
}
|
|
28
|
+
interface MinimumAmountValidatorOptions {
|
|
29
|
+
converter?: FiatConverter | undefined;
|
|
30
|
+
minimumUsdAmount?: number | undefined;
|
|
31
|
+
}
|
|
32
|
+
declare class MinimumAmountPolicy {
|
|
33
|
+
private readonly converter;
|
|
34
|
+
private readonly minimumUsdAmount;
|
|
35
|
+
constructor(options?: MinimumAmountValidatorOptions);
|
|
36
|
+
assertFiatAmountEligible(amount: number, fiatCurrency: FiatCurrency): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
declare function assertPaymentModeSupported(paymentType: 'PAYMENT' | 'DEPOSIT', cryptoCurrency: CryptoCurrency): void;
|
|
39
|
+
|
|
40
|
+
interface RetryOptions {
|
|
41
|
+
maxRetries?: number;
|
|
42
|
+
retryStatusCodes?: number[];
|
|
43
|
+
}
|
|
44
|
+
interface KryptoExpressClientOptions {
|
|
45
|
+
apiKey?: string | undefined;
|
|
46
|
+
baseUrl?: string | undefined;
|
|
47
|
+
timeoutMs?: number | undefined;
|
|
48
|
+
retry?: RetryOptions | undefined;
|
|
49
|
+
fetch?: typeof fetch | undefined;
|
|
50
|
+
fiatConverter?: FiatConverter | undefined;
|
|
51
|
+
}
|
|
52
|
+
interface ResolvedClientOptions {
|
|
53
|
+
apiKey: string | undefined;
|
|
54
|
+
baseUrl: string;
|
|
55
|
+
timeoutMs: number;
|
|
56
|
+
retry: {
|
|
57
|
+
maxRetries: number;
|
|
58
|
+
retryStatusCodes: number[];
|
|
59
|
+
};
|
|
60
|
+
fetch: typeof fetch;
|
|
61
|
+
fiatConverter: FiatConverter | undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface RequestOptions {
|
|
65
|
+
path: string;
|
|
66
|
+
method?: 'GET' | 'POST';
|
|
67
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
68
|
+
body?: unknown;
|
|
69
|
+
requiresAuth?: boolean;
|
|
70
|
+
}
|
|
71
|
+
declare class HttpClient {
|
|
72
|
+
private readonly options;
|
|
73
|
+
constructor(options: ResolvedClientOptions);
|
|
74
|
+
request<T>(request: RequestOptions): Promise<T>;
|
|
75
|
+
private buildHeaders;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface PaymentRecord {
|
|
79
|
+
id: number;
|
|
80
|
+
paymentType: PaymentType;
|
|
81
|
+
fiatCurrency: FiatCurrency;
|
|
82
|
+
fiatAmount: number | null;
|
|
83
|
+
cryptoAmount: number | null;
|
|
84
|
+
cryptoCurrency: CryptoCurrency;
|
|
85
|
+
expireDatetime: number;
|
|
86
|
+
createDatetime: number;
|
|
87
|
+
paidAt: number | null;
|
|
88
|
+
address: string;
|
|
89
|
+
isPaid: boolean;
|
|
90
|
+
isWithdrawn: boolean;
|
|
91
|
+
hash: string;
|
|
92
|
+
callbackUrl: string | null;
|
|
93
|
+
}
|
|
94
|
+
interface CreatePaymentInput {
|
|
95
|
+
fiatCurrency: FiatCurrency;
|
|
96
|
+
fiatAmount: number;
|
|
97
|
+
cryptoCurrency: CryptoCurrency;
|
|
98
|
+
callbackUrl?: string;
|
|
99
|
+
callbackSecret?: string;
|
|
100
|
+
}
|
|
101
|
+
interface CreateDepositInput {
|
|
102
|
+
fiatCurrency: FiatCurrency;
|
|
103
|
+
cryptoCurrency: CryptoCurrency;
|
|
104
|
+
callbackUrl?: string;
|
|
105
|
+
callbackSecret?: string;
|
|
106
|
+
}
|
|
107
|
+
interface CreatePaymentRequest extends CreatePaymentInput {
|
|
108
|
+
paymentType: 'PAYMENT';
|
|
109
|
+
}
|
|
110
|
+
interface CreateDepositRequest extends CreateDepositInput {
|
|
111
|
+
paymentType: 'DEPOSIT';
|
|
112
|
+
}
|
|
113
|
+
type CreatePaymentOrDepositRequest = CreatePaymentRequest | CreateDepositRequest;
|
|
114
|
+
interface WalletBalances {
|
|
115
|
+
[currencyCode: string]: number;
|
|
116
|
+
}
|
|
117
|
+
interface WithdrawalRequestBase {
|
|
118
|
+
cryptoCurrency: CryptoCurrency;
|
|
119
|
+
toAddress: string;
|
|
120
|
+
onlyCalculate?: boolean;
|
|
121
|
+
}
|
|
122
|
+
interface WithdrawAllInput extends WithdrawalRequestBase {
|
|
123
|
+
withdrawType: 'ALL';
|
|
124
|
+
}
|
|
125
|
+
interface WithdrawSingleInput extends WithdrawalRequestBase {
|
|
126
|
+
withdrawType: 'SINGLE';
|
|
127
|
+
paymentId: number;
|
|
128
|
+
}
|
|
129
|
+
type WithdrawalRequest = WithdrawAllInput | WithdrawSingleInput;
|
|
130
|
+
interface WithdrawalResponse {
|
|
131
|
+
id: number;
|
|
132
|
+
withdrawType: WithdrawType;
|
|
133
|
+
paymentId: number | null;
|
|
134
|
+
cryptoCurrency: CryptoCurrency;
|
|
135
|
+
toAddress: string;
|
|
136
|
+
txIdList: string[];
|
|
137
|
+
receivingAmount: number;
|
|
138
|
+
blockchainFeeAmount: number;
|
|
139
|
+
serviceFeeAmount: number;
|
|
140
|
+
onlyCalculate: boolean;
|
|
141
|
+
totalWithdrawalAmount: number;
|
|
142
|
+
createDatetime: number;
|
|
143
|
+
}
|
|
144
|
+
interface CryptoPrice {
|
|
145
|
+
cryptoCurrency: CryptoCurrency;
|
|
146
|
+
fiatCurrency: FiatCurrency;
|
|
147
|
+
price: number;
|
|
148
|
+
}
|
|
149
|
+
interface CallbackVerificationResult<T = unknown> {
|
|
150
|
+
isValid: boolean;
|
|
151
|
+
payload?: T;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface GetPricesInput {
|
|
155
|
+
cryptoCurrency: CryptoCurrency[];
|
|
156
|
+
fiatCurrency: FiatCurrency;
|
|
157
|
+
}
|
|
158
|
+
declare class CurrenciesResource {
|
|
159
|
+
private readonly httpClient;
|
|
160
|
+
constructor(httpClient: HttpClient);
|
|
161
|
+
listNative(): Promise<NativeCryptoCurrency[]>;
|
|
162
|
+
listAll(): Promise<CryptoCurrency[]>;
|
|
163
|
+
listStable(): Promise<StableCryptoCurrency[]>;
|
|
164
|
+
getPrices(input: GetPricesInput): Promise<CryptoPrice[]>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
declare class FiatResource {
|
|
168
|
+
private readonly httpClient;
|
|
169
|
+
constructor(httpClient: HttpClient);
|
|
170
|
+
list(): Promise<FiatCurrency[]>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare class PaymentsResource {
|
|
174
|
+
private readonly httpClient;
|
|
175
|
+
private readonly minimumAmountPolicy;
|
|
176
|
+
constructor(httpClient: HttpClient, minimumAmountPolicy: MinimumAmountPolicy);
|
|
177
|
+
create(input: CreatePaymentOrDepositRequest): Promise<PaymentRecord>;
|
|
178
|
+
createPayment(input: CreatePaymentInput | CreatePaymentRequest): Promise<PaymentRecord>;
|
|
179
|
+
createDeposit(input: CreateDepositInput | CreateDepositRequest): Promise<PaymentRecord>;
|
|
180
|
+
getByHash(hash: string): Promise<PaymentRecord>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare class WalletResource {
|
|
184
|
+
private readonly httpClient;
|
|
185
|
+
constructor(httpClient: HttpClient);
|
|
186
|
+
get(): Promise<WalletBalances>;
|
|
187
|
+
withdraw(input: WithdrawAllInput | WithdrawSingleInput): Promise<WithdrawalResponse>;
|
|
188
|
+
calculate(input: WithdrawAllInput | WithdrawSingleInput): Promise<WithdrawalResponse>;
|
|
189
|
+
withdrawAll(input: Omit<WithdrawAllInput, 'withdrawType' | 'onlyCalculate'>): Promise<WithdrawalResponse>;
|
|
190
|
+
withdrawSingle(input: Omit<WithdrawSingleInput, 'withdrawType' | 'onlyCalculate'>): Promise<WithdrawalResponse>;
|
|
191
|
+
calculateAll(input: Omit<WithdrawAllInput, 'withdrawType' | 'onlyCalculate'>): Promise<WithdrawalResponse>;
|
|
192
|
+
calculateSingle(input: Omit<WithdrawSingleInput, 'withdrawType' | 'onlyCalculate'>): Promise<WithdrawalResponse>;
|
|
193
|
+
private assertWithdrawalInput;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
declare class KryptoExpressClient {
|
|
197
|
+
readonly payments: PaymentsResource;
|
|
198
|
+
readonly wallet: WalletResource;
|
|
199
|
+
readonly currencies: CurrenciesResource;
|
|
200
|
+
readonly fiat: FiatResource;
|
|
201
|
+
constructor(options?: KryptoExpressClientOptions);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
interface ErrorOptions {
|
|
205
|
+
cause?: unknown;
|
|
206
|
+
statusCode?: number;
|
|
207
|
+
code?: string;
|
|
208
|
+
details?: unknown;
|
|
209
|
+
}
|
|
210
|
+
declare class SDKError extends Error {
|
|
211
|
+
readonly cause: unknown;
|
|
212
|
+
constructor(message: string, options?: ErrorOptions);
|
|
213
|
+
}
|
|
214
|
+
declare class ValidationError extends SDKError {
|
|
215
|
+
readonly details: unknown;
|
|
216
|
+
constructor(message: string, options?: ErrorOptions);
|
|
217
|
+
}
|
|
218
|
+
declare class UnsupportedPaymentModeError extends ValidationError {
|
|
219
|
+
}
|
|
220
|
+
declare class MinimumAmountError extends ValidationError {
|
|
221
|
+
readonly minimumUsdAmount: number;
|
|
222
|
+
constructor(message: string, minimumUsdAmount?: number, options?: ErrorOptions);
|
|
223
|
+
}
|
|
224
|
+
declare class CurrencyConversionError extends ValidationError {
|
|
225
|
+
}
|
|
226
|
+
declare class APIError extends SDKError {
|
|
227
|
+
readonly statusCode: number;
|
|
228
|
+
readonly code: string | undefined;
|
|
229
|
+
readonly details: unknown;
|
|
230
|
+
constructor(message: string, statusCode: number, options?: ErrorOptions);
|
|
231
|
+
}
|
|
232
|
+
declare class AuthError extends APIError {
|
|
233
|
+
}
|
|
234
|
+
declare class RateLimitError extends APIError {
|
|
235
|
+
}
|
|
236
|
+
declare class NotFoundError extends APIError {
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
interface VerifyCallbackSignatureInput {
|
|
240
|
+
rawBody: string;
|
|
241
|
+
callbackSecret: string;
|
|
242
|
+
signature: string | null | undefined;
|
|
243
|
+
}
|
|
244
|
+
declare function compactJson(rawBody: string): string;
|
|
245
|
+
declare function computeCallbackSignature(rawBody: string, callbackSecret: string): string;
|
|
246
|
+
declare function verifyCallbackSignature(input: VerifyCallbackSignatureInput): boolean;
|
|
247
|
+
|
|
248
|
+
export { ALL_CRYPTO_CURRENCIES, APIError, AuthError, type CallbackVerificationResult, type CreateDepositInput, type CreateDepositRequest, type CreatePaymentInput, type CreatePaymentOrDepositRequest, type CreatePaymentRequest, type CryptoCurrency, type CryptoPrice, CurrencyConversionError, type ErrorOptions, FIAT_CURRENCIES, type FiatConversionQuote, type FiatConverter, type FiatCurrency, KryptoExpressClient, type KryptoExpressClientOptions, MinimumAmountError, MinimumAmountPolicy, type MinimumAmountValidatorOptions, NATIVE_CRYPTO_CURRENCIES, type NativeCryptoCurrency, NotFoundError, PAYMENT_TYPES, type PaymentRecord, type PaymentType, RateLimitError, SDKError, STABLE_CRYPTO_CURRENCIES, type StableCryptoCurrency, StaticRateFiatConverter, UnsupportedPaymentModeError, ValidationError, type VerifyCallbackSignatureInput, WITHDRAW_TYPES, type WalletBalances, type WithdrawAllInput, type WithdrawSingleInput, type WithdrawType, type WithdrawalRequest, type WithdrawalRequestBase, type WithdrawalResponse, assertPaymentModeSupported, compactJson, computeCallbackSignature, isStableCryptoCurrency, verifyCallbackSignature };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
declare const FIAT_CURRENCIES: readonly ["USD", "EUR", "GBP", "JPY", "CHF", "AUD", "CAD", "CNY", "HKD", "SGD", "SEK", "NOK", "DKK", "PLN", "CZK", "HUF", "TRY", "INR", "KRW", "THB", "IDR", "MYR", "PHP", "VND", "AED", "SAR", "ZAR", "NGN", "KES", "GHS", "BRL", "MXN", "ARS", "CLP", "COP", "PEN", "RUB", "UAH", "ILS", "PKR", "BDT", "LKR", "TWD", "BHD", "KWD", "RON", "NZD"];
|
|
2
|
+
declare const NATIVE_CRYPTO_CURRENCIES: readonly ["BTC", "LTC", "ETH", "SOL", "BNB", "DOGE"];
|
|
3
|
+
declare const STABLE_CRYPTO_CURRENCIES: readonly ["USDC_ERC20", "USDT_ERC20", "USDT_BEP20", "USDC_BEP20", "USDT_SOL", "USDC_SOL"];
|
|
4
|
+
declare const ALL_CRYPTO_CURRENCIES: readonly ["BTC", "LTC", "ETH", "SOL", "BNB", "DOGE", "USDC_ERC20", "USDT_ERC20", "USDT_BEP20", "USDC_BEP20", "USDT_SOL", "USDC_SOL"];
|
|
5
|
+
declare const PAYMENT_TYPES: readonly ["PAYMENT", "DEPOSIT"];
|
|
6
|
+
declare const WITHDRAW_TYPES: readonly ["ALL", "SINGLE"];
|
|
7
|
+
type FiatCurrency = (typeof FIAT_CURRENCIES)[number];
|
|
8
|
+
type NativeCryptoCurrency = (typeof NATIVE_CRYPTO_CURRENCIES)[number];
|
|
9
|
+
type StableCryptoCurrency = (typeof STABLE_CRYPTO_CURRENCIES)[number];
|
|
10
|
+
type CryptoCurrency = (typeof ALL_CRYPTO_CURRENCIES)[number];
|
|
11
|
+
type PaymentType = (typeof PAYMENT_TYPES)[number];
|
|
12
|
+
type WithdrawType = (typeof WITHDRAW_TYPES)[number];
|
|
13
|
+
declare function isStableCryptoCurrency(value: string): value is StableCryptoCurrency;
|
|
14
|
+
|
|
15
|
+
interface FiatConversionQuote {
|
|
16
|
+
from: FiatCurrency;
|
|
17
|
+
to: FiatCurrency;
|
|
18
|
+
rate: number;
|
|
19
|
+
}
|
|
20
|
+
interface FiatConverter {
|
|
21
|
+
convert(amount: number, from: FiatCurrency, to: FiatCurrency): Promise<number>;
|
|
22
|
+
}
|
|
23
|
+
declare class StaticRateFiatConverter implements FiatConverter {
|
|
24
|
+
private readonly rates;
|
|
25
|
+
constructor(quotes: FiatConversionQuote[]);
|
|
26
|
+
convert(amount: number, from: FiatCurrency, to: FiatCurrency): Promise<number>;
|
|
27
|
+
}
|
|
28
|
+
interface MinimumAmountValidatorOptions {
|
|
29
|
+
converter?: FiatConverter | undefined;
|
|
30
|
+
minimumUsdAmount?: number | undefined;
|
|
31
|
+
}
|
|
32
|
+
declare class MinimumAmountPolicy {
|
|
33
|
+
private readonly converter;
|
|
34
|
+
private readonly minimumUsdAmount;
|
|
35
|
+
constructor(options?: MinimumAmountValidatorOptions);
|
|
36
|
+
assertFiatAmountEligible(amount: number, fiatCurrency: FiatCurrency): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
declare function assertPaymentModeSupported(paymentType: 'PAYMENT' | 'DEPOSIT', cryptoCurrency: CryptoCurrency): void;
|
|
39
|
+
|
|
40
|
+
interface RetryOptions {
|
|
41
|
+
maxRetries?: number;
|
|
42
|
+
retryStatusCodes?: number[];
|
|
43
|
+
}
|
|
44
|
+
interface KryptoExpressClientOptions {
|
|
45
|
+
apiKey?: string | undefined;
|
|
46
|
+
baseUrl?: string | undefined;
|
|
47
|
+
timeoutMs?: number | undefined;
|
|
48
|
+
retry?: RetryOptions | undefined;
|
|
49
|
+
fetch?: typeof fetch | undefined;
|
|
50
|
+
fiatConverter?: FiatConverter | undefined;
|
|
51
|
+
}
|
|
52
|
+
interface ResolvedClientOptions {
|
|
53
|
+
apiKey: string | undefined;
|
|
54
|
+
baseUrl: string;
|
|
55
|
+
timeoutMs: number;
|
|
56
|
+
retry: {
|
|
57
|
+
maxRetries: number;
|
|
58
|
+
retryStatusCodes: number[];
|
|
59
|
+
};
|
|
60
|
+
fetch: typeof fetch;
|
|
61
|
+
fiatConverter: FiatConverter | undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface RequestOptions {
|
|
65
|
+
path: string;
|
|
66
|
+
method?: 'GET' | 'POST';
|
|
67
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
68
|
+
body?: unknown;
|
|
69
|
+
requiresAuth?: boolean;
|
|
70
|
+
}
|
|
71
|
+
declare class HttpClient {
|
|
72
|
+
private readonly options;
|
|
73
|
+
constructor(options: ResolvedClientOptions);
|
|
74
|
+
request<T>(request: RequestOptions): Promise<T>;
|
|
75
|
+
private buildHeaders;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface PaymentRecord {
|
|
79
|
+
id: number;
|
|
80
|
+
paymentType: PaymentType;
|
|
81
|
+
fiatCurrency: FiatCurrency;
|
|
82
|
+
fiatAmount: number | null;
|
|
83
|
+
cryptoAmount: number | null;
|
|
84
|
+
cryptoCurrency: CryptoCurrency;
|
|
85
|
+
expireDatetime: number;
|
|
86
|
+
createDatetime: number;
|
|
87
|
+
paidAt: number | null;
|
|
88
|
+
address: string;
|
|
89
|
+
isPaid: boolean;
|
|
90
|
+
isWithdrawn: boolean;
|
|
91
|
+
hash: string;
|
|
92
|
+
callbackUrl: string | null;
|
|
93
|
+
}
|
|
94
|
+
interface CreatePaymentInput {
|
|
95
|
+
fiatCurrency: FiatCurrency;
|
|
96
|
+
fiatAmount: number;
|
|
97
|
+
cryptoCurrency: CryptoCurrency;
|
|
98
|
+
callbackUrl?: string;
|
|
99
|
+
callbackSecret?: string;
|
|
100
|
+
}
|
|
101
|
+
interface CreateDepositInput {
|
|
102
|
+
fiatCurrency: FiatCurrency;
|
|
103
|
+
cryptoCurrency: CryptoCurrency;
|
|
104
|
+
callbackUrl?: string;
|
|
105
|
+
callbackSecret?: string;
|
|
106
|
+
}
|
|
107
|
+
interface CreatePaymentRequest extends CreatePaymentInput {
|
|
108
|
+
paymentType: 'PAYMENT';
|
|
109
|
+
}
|
|
110
|
+
interface CreateDepositRequest extends CreateDepositInput {
|
|
111
|
+
paymentType: 'DEPOSIT';
|
|
112
|
+
}
|
|
113
|
+
type CreatePaymentOrDepositRequest = CreatePaymentRequest | CreateDepositRequest;
|
|
114
|
+
interface WalletBalances {
|
|
115
|
+
[currencyCode: string]: number;
|
|
116
|
+
}
|
|
117
|
+
interface WithdrawalRequestBase {
|
|
118
|
+
cryptoCurrency: CryptoCurrency;
|
|
119
|
+
toAddress: string;
|
|
120
|
+
onlyCalculate?: boolean;
|
|
121
|
+
}
|
|
122
|
+
interface WithdrawAllInput extends WithdrawalRequestBase {
|
|
123
|
+
withdrawType: 'ALL';
|
|
124
|
+
}
|
|
125
|
+
interface WithdrawSingleInput extends WithdrawalRequestBase {
|
|
126
|
+
withdrawType: 'SINGLE';
|
|
127
|
+
paymentId: number;
|
|
128
|
+
}
|
|
129
|
+
type WithdrawalRequest = WithdrawAllInput | WithdrawSingleInput;
|
|
130
|
+
interface WithdrawalResponse {
|
|
131
|
+
id: number;
|
|
132
|
+
withdrawType: WithdrawType;
|
|
133
|
+
paymentId: number | null;
|
|
134
|
+
cryptoCurrency: CryptoCurrency;
|
|
135
|
+
toAddress: string;
|
|
136
|
+
txIdList: string[];
|
|
137
|
+
receivingAmount: number;
|
|
138
|
+
blockchainFeeAmount: number;
|
|
139
|
+
serviceFeeAmount: number;
|
|
140
|
+
onlyCalculate: boolean;
|
|
141
|
+
totalWithdrawalAmount: number;
|
|
142
|
+
createDatetime: number;
|
|
143
|
+
}
|
|
144
|
+
interface CryptoPrice {
|
|
145
|
+
cryptoCurrency: CryptoCurrency;
|
|
146
|
+
fiatCurrency: FiatCurrency;
|
|
147
|
+
price: number;
|
|
148
|
+
}
|
|
149
|
+
interface CallbackVerificationResult<T = unknown> {
|
|
150
|
+
isValid: boolean;
|
|
151
|
+
payload?: T;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface GetPricesInput {
|
|
155
|
+
cryptoCurrency: CryptoCurrency[];
|
|
156
|
+
fiatCurrency: FiatCurrency;
|
|
157
|
+
}
|
|
158
|
+
declare class CurrenciesResource {
|
|
159
|
+
private readonly httpClient;
|
|
160
|
+
constructor(httpClient: HttpClient);
|
|
161
|
+
listNative(): Promise<NativeCryptoCurrency[]>;
|
|
162
|
+
listAll(): Promise<CryptoCurrency[]>;
|
|
163
|
+
listStable(): Promise<StableCryptoCurrency[]>;
|
|
164
|
+
getPrices(input: GetPricesInput): Promise<CryptoPrice[]>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
declare class FiatResource {
|
|
168
|
+
private readonly httpClient;
|
|
169
|
+
constructor(httpClient: HttpClient);
|
|
170
|
+
list(): Promise<FiatCurrency[]>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare class PaymentsResource {
|
|
174
|
+
private readonly httpClient;
|
|
175
|
+
private readonly minimumAmountPolicy;
|
|
176
|
+
constructor(httpClient: HttpClient, minimumAmountPolicy: MinimumAmountPolicy);
|
|
177
|
+
create(input: CreatePaymentOrDepositRequest): Promise<PaymentRecord>;
|
|
178
|
+
createPayment(input: CreatePaymentInput | CreatePaymentRequest): Promise<PaymentRecord>;
|
|
179
|
+
createDeposit(input: CreateDepositInput | CreateDepositRequest): Promise<PaymentRecord>;
|
|
180
|
+
getByHash(hash: string): Promise<PaymentRecord>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare class WalletResource {
|
|
184
|
+
private readonly httpClient;
|
|
185
|
+
constructor(httpClient: HttpClient);
|
|
186
|
+
get(): Promise<WalletBalances>;
|
|
187
|
+
withdraw(input: WithdrawAllInput | WithdrawSingleInput): Promise<WithdrawalResponse>;
|
|
188
|
+
calculate(input: WithdrawAllInput | WithdrawSingleInput): Promise<WithdrawalResponse>;
|
|
189
|
+
withdrawAll(input: Omit<WithdrawAllInput, 'withdrawType' | 'onlyCalculate'>): Promise<WithdrawalResponse>;
|
|
190
|
+
withdrawSingle(input: Omit<WithdrawSingleInput, 'withdrawType' | 'onlyCalculate'>): Promise<WithdrawalResponse>;
|
|
191
|
+
calculateAll(input: Omit<WithdrawAllInput, 'withdrawType' | 'onlyCalculate'>): Promise<WithdrawalResponse>;
|
|
192
|
+
calculateSingle(input: Omit<WithdrawSingleInput, 'withdrawType' | 'onlyCalculate'>): Promise<WithdrawalResponse>;
|
|
193
|
+
private assertWithdrawalInput;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
declare class KryptoExpressClient {
|
|
197
|
+
readonly payments: PaymentsResource;
|
|
198
|
+
readonly wallet: WalletResource;
|
|
199
|
+
readonly currencies: CurrenciesResource;
|
|
200
|
+
readonly fiat: FiatResource;
|
|
201
|
+
constructor(options?: KryptoExpressClientOptions);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
interface ErrorOptions {
|
|
205
|
+
cause?: unknown;
|
|
206
|
+
statusCode?: number;
|
|
207
|
+
code?: string;
|
|
208
|
+
details?: unknown;
|
|
209
|
+
}
|
|
210
|
+
declare class SDKError extends Error {
|
|
211
|
+
readonly cause: unknown;
|
|
212
|
+
constructor(message: string, options?: ErrorOptions);
|
|
213
|
+
}
|
|
214
|
+
declare class ValidationError extends SDKError {
|
|
215
|
+
readonly details: unknown;
|
|
216
|
+
constructor(message: string, options?: ErrorOptions);
|
|
217
|
+
}
|
|
218
|
+
declare class UnsupportedPaymentModeError extends ValidationError {
|
|
219
|
+
}
|
|
220
|
+
declare class MinimumAmountError extends ValidationError {
|
|
221
|
+
readonly minimumUsdAmount: number;
|
|
222
|
+
constructor(message: string, minimumUsdAmount?: number, options?: ErrorOptions);
|
|
223
|
+
}
|
|
224
|
+
declare class CurrencyConversionError extends ValidationError {
|
|
225
|
+
}
|
|
226
|
+
declare class APIError extends SDKError {
|
|
227
|
+
readonly statusCode: number;
|
|
228
|
+
readonly code: string | undefined;
|
|
229
|
+
readonly details: unknown;
|
|
230
|
+
constructor(message: string, statusCode: number, options?: ErrorOptions);
|
|
231
|
+
}
|
|
232
|
+
declare class AuthError extends APIError {
|
|
233
|
+
}
|
|
234
|
+
declare class RateLimitError extends APIError {
|
|
235
|
+
}
|
|
236
|
+
declare class NotFoundError extends APIError {
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
interface VerifyCallbackSignatureInput {
|
|
240
|
+
rawBody: string;
|
|
241
|
+
callbackSecret: string;
|
|
242
|
+
signature: string | null | undefined;
|
|
243
|
+
}
|
|
244
|
+
declare function compactJson(rawBody: string): string;
|
|
245
|
+
declare function computeCallbackSignature(rawBody: string, callbackSecret: string): string;
|
|
246
|
+
declare function verifyCallbackSignature(input: VerifyCallbackSignatureInput): boolean;
|
|
247
|
+
|
|
248
|
+
export { ALL_CRYPTO_CURRENCIES, APIError, AuthError, type CallbackVerificationResult, type CreateDepositInput, type CreateDepositRequest, type CreatePaymentInput, type CreatePaymentOrDepositRequest, type CreatePaymentRequest, type CryptoCurrency, type CryptoPrice, CurrencyConversionError, type ErrorOptions, FIAT_CURRENCIES, type FiatConversionQuote, type FiatConverter, type FiatCurrency, KryptoExpressClient, type KryptoExpressClientOptions, MinimumAmountError, MinimumAmountPolicy, type MinimumAmountValidatorOptions, NATIVE_CRYPTO_CURRENCIES, type NativeCryptoCurrency, NotFoundError, PAYMENT_TYPES, type PaymentRecord, type PaymentType, RateLimitError, SDKError, STABLE_CRYPTO_CURRENCIES, type StableCryptoCurrency, StaticRateFiatConverter, UnsupportedPaymentModeError, ValidationError, type VerifyCallbackSignatureInput, WITHDRAW_TYPES, type WalletBalances, type WithdrawAllInput, type WithdrawSingleInput, type WithdrawType, type WithdrawalRequest, type WithdrawalRequestBase, type WithdrawalResponse, assertPaymentModeSupported, compactJson, computeCallbackSignature, isStableCryptoCurrency, verifyCallbackSignature };
|