@100pay-hq/100pay.js 1.3.2 → 1.3.4

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// src/index.ts\n\nimport axios, { AxiosError, AxiosResponse } from \"axios\";\nimport * as crypto from \"crypto\";\nimport {\n CreateSubAccountData,\n CreateSubAccountResponse,\n} from \"./types/subAccount\";\nimport {\n CurrencyConversionPayload,\n CurrencyConversionResult,\n ISupportedWalletResponse,\n} from \"./types\";\nimport {\n ITransferAssetData,\n ITransferAssetResponse,\n ITransferHistoryParams,\n ITransferHistoryResponse,\n ITransferFeeParams,\n ITransferFeeResponse,\n} from \"./types/transfer\";\nimport { logger } from \"@untools/logger\";\n\n/**\n * Configuration interface for initializing the Pay100 SDK\n * @property publicKey - API public key required for all API calls\n * @property secretKey - Secret key used for server-side authentication and request signing\n * @property baseUrl - Optional API base URL, defaults to production endpoint\n */\ninterface IPay100Config {\n publicKey: string;\n secretKey?: string;\n baseUrl?: string;\n}\n\n/**\n * Interface representing transaction data returned from payment verification\n * Flexible structure to accommodate various transaction types and properties\n */\ninterface ITransactionData {\n [key: string]: unknown;\n}\n\n/**\n * Interface for raw API responses before processing\n * Provides a flexible structure while capturing common response elements\n */\ninterface IRawApiResponse {\n status?: string;\n message?: string;\n data?: unknown;\n [key: string]: unknown;\n}\n\n/**\n * Standardized response interface for transaction verification\n * @property status - Result status ('success' or 'error')\n * @property data - Transaction details when successful, empty object on failure\n * @property message - Optional response message, typically present on errors\n */\ninterface IVerifyResponse {\n status: \"success\" | \"error\";\n data: ITransactionData | Record<string, never>;\n message?: string;\n}\n\n// Default API endpoint if not otherwise specified\nconst BASE_URL = process.env.BASE_URL || \"https://api.100pay.co\";\n\n/**\n * Custom error class for payment verification failures\n * Provides consistent error structure for better error handling\n */\nexport class PaymentVerificationError extends Error {\n status: string;\n data: Record<string, never>;\n\n constructor(message: string) {\n super(message);\n this.name = \"PaymentVerificationError\";\n this.status = \"error\";\n this.data = {};\n }\n}\n\n/**\n * Main SDK class for interacting with the 100Pay payment platform\n * Provides methods for transaction verification, subaccount management,\n * currency conversion, and asset transfers\n */\nexport class Pay100 {\n private publicKey: string;\n private secretKey?: string;\n private baseUrl: string;\n\n /**\n * Initialize the Pay100 SDK\n * @param config - Configuration object containing API keys and optional base URL\n */\n constructor({ publicKey, secretKey, baseUrl = BASE_URL }: IPay100Config) {\n this.publicKey = publicKey;\n this.secretKey = secretKey;\n this.baseUrl = baseUrl;\n }\n\n /**\n * Creates a cryptographic signature for secure server-to-server communication\n *\n * @param payload - Request payload that needs to be signed\n * @returns Object containing current timestamp and HMAC SHA-256 signature\n * @throws Error if secret key is missing or invalid\n */\n private createSignature(payload: Record<string, unknown>): {\n timestamp: string;\n signature: string;\n } {\n const timestamp = Date.now().toString();\n\n // Extract the token part from the secret key if it's in the format\n // STATUS;TYPE;TOKEN (e.g., \"LIVE;SK;eyJhbGciOiJIUzI1...\")\n let signingSecret = this?.secretKey;\n\n if (this?.secretKey?.includes(\";\")) {\n const secretKeyParts = this.secretKey.split(\";\");\n if (secretKeyParts.length === 3) {\n // Use just the token part as the signing secret\n signingSecret = secretKeyParts[2];\n }\n }\n\n if (!signingSecret) {\n throw new Error(\"Secret key is required for signing\");\n }\n\n // Create signature using HMAC SHA-256\n const signature = crypto\n .createHmac(\"sha256\", signingSecret)\n .update(timestamp + JSON.stringify(payload))\n .digest(\"hex\");\n\n return { timestamp, signature };\n }\n\n /**\n * Constructs HTTP headers for API requests with optional authentication\n *\n * @param payload - Request payload used to generate security signature\n * @returns Object containing all necessary HTTP headers\n */\n private getHeaders(\n payload: Record<string, unknown> = {}\n ): Record<string, string> {\n // Generate authentication headers if secret key is available (server-side mode)\n if (this.secretKey) {\n const { timestamp, signature } = this.createSignature(payload);\n return {\n \"api-key\": this.publicKey,\n \"x-secret-key\": this.secretKey,\n \"x-timestamp\": timestamp,\n \"x-signature\": signature,\n \"Content-Type\": \"application/json\",\n };\n }\n\n // Basic headers for public API usage (client-side mode)\n return {\n \"api-key\": this.publicKey,\n \"Content-Type\": \"application/json\",\n };\n }\n\n /**\n * Verifies the status and details of a payment transaction\n *\n * @param transactionId - Unique identifier of the transaction to verify\n * @returns Promise resolving to verification result with transaction data\n * @throws PaymentVerificationError on network issues or invalid responses\n */\n verify = async (transactionId: string): Promise<IVerifyResponse> => {\n try {\n const payload = { transactionId };\n\n const response: AxiosResponse<IRawApiResponse> = await axios({\n method: \"POST\",\n url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,\n headers: this.getHeaders(payload),\n data: payload,\n });\n\n // Handle empty response\n if (!response.data) {\n return {\n status: \"error\",\n data: {},\n message:\n \"Something went wrong, be sure you supplied a valid payment id.\",\n };\n }\n\n // Handle string responses which indicate errors\n if (typeof response.data === \"string\") {\n if (response.data === \"Access Denied, Invalid KEY supplied\") {\n return {\n status: \"error\",\n data: {},\n message: \"Access Denied, Invalid KEY supplied\",\n };\n }\n\n if (response.data === \"invalid payment id supplied\") {\n return {\n status: \"error\",\n data: {},\n };\n }\n }\n\n // Validate and transform response data to ensure type safety\n const responseData = response.data;\n\n // Ensure the response data is an object that can be safely cast to ITransactionData\n const transactionData: ITransactionData =\n responseData && typeof responseData === \"object\"\n ? (responseData as ITransactionData)\n : {};\n\n // Return successful response with properly typed data\n return {\n status: \"success\",\n data: transactionData,\n };\n } catch (error) {\n // Handle Axios errors with detailed message\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n throw new PaymentVerificationError(\n axiosError.message ||\n \"Something went wrong, be sure you supplied a valid payment id.\"\n );\n }\n\n // Handle other errors with appropriate message\n throw new PaymentVerificationError(\n error instanceof Error ? error.message : \"An unknown error occurred\"\n );\n }\n };\n\n /**\n * Namespace for subaccount management operations\n * Provides methods to create and manage subaccounts\n */\n subaccounts = {\n /**\n * Creates a new subaccount within the platform\n *\n * @param data - Subaccount configuration including owner details and supported currencies\n * @returns Promise resolving to the created subaccount details\n * @throws Error if the request fails or returns invalid data\n */\n create: async (\n data: CreateSubAccountData\n ): Promise<CreateSubAccountResponse> => {\n // Make sure the networks are lowercase\n data.networks = data.networks.map((network) => network.toLowerCase());\n return this.request<CreateSubAccountResponse>(\n \"POST\",\n \"/api/v1/assets/subaccount/create\",\n data\n );\n },\n };\n\n /**\n * Namespace for currency conversion operations\n * Provides methods to calculate exchange rates and fees\n */\n conversion = {\n /**\n * Calculates a preview of currency conversion with rates and fees\n *\n * @param data - Conversion details including amount, source and target currencies\n * @returns Promise resolving to detailed conversion calculation\n * @throws Error if the request fails or returns invalid data\n */\n preview: async (\n data: CurrencyConversionPayload\n ): Promise<CurrencyConversionResult> => {\n return this.request<CurrencyConversionResult>(\n \"POST\",\n \"/api/v1/user/preview-convert-asset\",\n {\n amount: data.amount,\n to_symbol: data.toSymbol,\n from_symbol: data.fromSymbol,\n appId: data.appId,\n }\n );\n },\n };\n\n /**\n * Namespace for asset transfer operations\n * Provides methods to transfer assets, view history, and calculate fees\n */\n transfer = {\n /**\n * Transfer assets between wallets\n *\n * @param data - Transfer details including amount, currency, destination, and authentication\n * @returns Promise resolving to transfer confirmation with receipt and transaction ID\n * @throws Error if the transfer fails due to validation, insufficient funds, or other issues\n */\n executeTransfer: async (\n data: ITransferAssetData\n ): Promise<ITransferAssetResponse> => {\n return this.request<ITransferAssetResponse>(\n \"POST\",\n \"/api/v1/transfer/asset\",\n data\n );\n },\n\n /**\n * Get transfer history for the authenticated user\n *\n * @param params - Filtering and pagination parameters\n * @returns Promise resolving to paginated transfer history records\n * @throws Error if the request fails or authentication is invalid\n */\n getHistory: async (\n params: ITransferHistoryParams\n ): Promise<ITransferHistoryResponse> => {\n return this.request<ITransferHistoryResponse>(\n \"GET\",\n \"/api/v1/transfer/history\",\n params\n );\n },\n\n /**\n * Calculate transfer fees for a potential transaction\n *\n * @param params - Fee calculation parameters including currency and transfer type\n * @returns Promise resolving to detailed fee breakdown\n * @throws Error if the fee calculation fails or currency is not supported\n */\n calculateFee: async (\n params: ITransferFeeParams\n ): Promise<ITransferFeeResponse> => {\n return this.request<ITransferFeeResponse>(\n \"GET\",\n \"/api/v1/transfer/fee\",\n params\n );\n },\n };\n\n /**\n * Namespace for wallet operations\n * Provides methods to retrieve supported wallets\n */\n wallet = {\n /**\n * Get a list of supported wallets and their details\n *\n * @returns Promise resolving to an array of supported wallet configurations\n * @throws Error if the request fails or authentication is invalid\n */\n getSupportedWallets: async (): Promise<ISupportedWalletResponse> => {\n return this.request<ISupportedWalletResponse>(\n \"GET\",\n \"/api/v1/wallet/supported\"\n );\n },\n };\n\n /**\n * Generic method to make authenticated API requests to any endpoint\n *\n * @param method - HTTP method to use (GET, POST, PUT, DELETE)\n * @param endpoint - API endpoint path (will be appended to base URL)\n * @param data - Request payload or query parameters\n * @returns Promise resolving to the typed API response\n * @throws Error with detailed message on request failure\n */\n async request<T>(\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n endpoint: string,\n data: Record<string, unknown> = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n const headers = this.getHeaders(data);\n\n const response = await axios({\n method,\n url,\n headers,\n data: method !== \"GET\" ? data : undefined,\n params: method === \"GET\" ? data : undefined,\n });\n\n // Check if the response indicates an error despite a successful HTTP status\n if (\n response.data &&\n typeof response.data === \"object\" &&\n \"success\" in response.data\n ) {\n if ((response.data as { success?: boolean }).success === false) {\n // Extract error from the API's own error indication\n const errorMessage = this.extractErrorMessage(response.data);\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n }\n\n return response.data as T;\n } catch (error) {\n logger.error(error);\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n logger.error(axiosError?.response);\n\n // Extract error message from response data if available\n const errorMessage = axiosError.response?.data\n ? this.extractErrorMessage(axiosError.response.data)\n : axiosError.message;\n\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n\n // Rethrow original error if not an Axios error\n throw error;\n }\n }\n\n /**\n * Extracts error message from various response data structures\n *\n * @param data - The response data object which may contain error information\n * @returns The most specific error message available\n */\n private extractErrorMessage(data: unknown): string {\n // If data is a string, return it directly\n if (typeof data === \"string\") {\n return data;\n }\n\n // If data is not an object or is null, return a generic message\n if (typeof data !== \"object\" || data === null) {\n return \"Unknown error\";\n }\n\n // Handle different error structures\n const dataObj = data as Record<string, unknown>;\n\n // Direct error message in data.message\n if (\"message\" in dataObj && typeof dataObj.message === \"string\") {\n return dataObj.message;\n }\n\n // Error object with message property\n if (\"error\" in dataObj) {\n const error = dataObj.error;\n\n // String error\n if (typeof error === \"string\") {\n return error;\n }\n\n // Object error with message\n if (error && typeof error === \"object\") {\n const errorObj = error as Record<string, unknown>;\n\n if (\"message\" in errorObj && typeof errorObj.message === \"string\") {\n return errorObj.message;\n }\n\n // Try to get any useful information from the error object\n if (\"code\" in errorObj && typeof errorObj.code === \"string\") {\n return `Error code: ${errorObj.code}`;\n }\n }\n }\n\n // Look for error in the 'data' property\n if (\"data\" in dataObj && dataObj.data && typeof dataObj.data === \"object\") {\n const nestedData = dataObj.data as Record<string, unknown>;\n\n if (\"message\" in nestedData && typeof nestedData.message === \"string\") {\n return nestedData.message;\n }\n\n if (\n \"error\" in nestedData &&\n nestedData.error &&\n typeof nestedData.error === \"object\"\n ) {\n const nestedError = nestedData.error as Record<string, unknown>;\n if (\n \"message\" in nestedError &&\n typeof nestedError.message === \"string\"\n ) {\n return nestedError.message;\n }\n }\n }\n\n // If we have a statusText from the response, use that\n if (\"statusText\" in dataObj && typeof dataObj.statusText === \"string\") {\n return dataObj.statusText;\n }\n\n // Stringify the error if nothing else works\n try {\n return `Error details: ${JSON.stringify(dataObj)}`;\n } catch {\n return \"Unknown error occurred\";\n }\n }\n}\n\nexport * from \"./types\";\nexport * from \"./types/transfer\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAiD;AACjD,aAAwB;A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AAEjB,YAAI,aAAa,YAAY,OAAO,SAAS,YAAY,UAAU;AACjE,iBAAO,SAAS;AAAA,QAClB;AAGA,YAAI,UAAU,YAAY,OAAO,SAAS,SAAS,UAAU;AAC3D,iBAAO,eAAe,SAAS,IAAI;AAAA,QACrC;AAAA,MACF;AAAA,IACF;AAGA,QAAI,UAAU,WAAW,QAAQ,QAAQ,OAAO,QAAQ,SAAS,UAAU;AACzE,YAAM,aAAa,QAAQ;AAE3B,UAAI,aAAa,cAAc,OAAO,WAAW,YAAY,UAAU;AACrE,eAAO,WAAW;AAAA,MACpB;AAEA,UACE,WAAW,cACX,WAAW,SACX,OAAO,WAAW,UAAU,UAC5B;AACA,cAAM,cAAc,WAAW;AAC/B,YACE,aAAa,eACb,OAAO,YAAY,YAAY,UAC/B;AACA,iBAAO,YAAY;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAGA,QAAI,gBAAgB,WAAW,OAAO,QAAQ,eAAe,UAAU;AACrE,aAAO,QAAQ;AAAA,IACjB;AAGA,QAAI;AACF,aAAO,kBAAkB,KAAK,UAAU,OAAO,CAAC;AAAA,IAClD,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["axios"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// src/index.ts\n\nimport axios, { AxiosError, AxiosResponse } from \"axios\";\nimport * as crypto from \"crypto\";\nimport {\n CreateSubAccountData,\n CreateSubAccountResponse,\n} from \"./types/subAccount\";\nimport {\n CurrencyConversionPayload,\n CurrencyConversionResult,\n ISupportedWalletResponse,\n IVerifyResponse,\n} from \"./types\";\nimport {\n ITransferAssetData,\n ITransferAssetResponse,\n ITransferHistoryParams,\n ITransferHistoryResponse,\n ITransferFeeParams,\n ITransferFeeResponse,\n} from \"./types/transfer\";\nimport { logger } from \"@untools/logger\";\n\n/**\n * Configuration interface for initializing the Pay100 SDK\n * @property publicKey - API public key required for all API calls\n * @property secretKey - Secret key used for server-side authentication and request signing\n * @property baseUrl - Optional API base URL, defaults to production endpoint\n */\ninterface IPay100Config {\n publicKey: string;\n secretKey?: string;\n baseUrl?: string;\n}\n\n/**\n * Interface representing transaction data returned from payment verification\n * Flexible structure to accommodate various transaction types and properties\n */\nexport interface ITransactionData {\n [key: string]: unknown;\n}\n\n/**\n * Interface for raw API responses before processing\n * Provides a flexible structure while capturing common response elements\n */\ninterface IRawApiResponse {\n status?: string;\n message?: string;\n data?: unknown;\n [key: string]: unknown;\n}\n\n// Default API endpoint if not otherwise specified\nconst BASE_URL = process.env.BASE_URL || \"https://api.100pay.co\";\n\n/**\n * Custom error class for payment verification failures\n * Provides consistent error structure for better error handling\n */\nexport class PaymentVerificationError extends Error {\n status: string;\n data: Record<string, never>;\n\n constructor(message: string) {\n super(message);\n this.name = \"PaymentVerificationError\";\n this.status = \"error\";\n this.data = {};\n }\n}\n\n/**\n * Main SDK class for interacting with the 100Pay payment platform\n * Provides methods for transaction verification, subaccount management,\n * currency conversion, and asset transfers\n */\nexport class Pay100 {\n private publicKey: string;\n private secretKey?: string;\n private baseUrl: string;\n\n /**\n * Initialize the Pay100 SDK\n * @param config - Configuration object containing API keys and optional base URL\n */\n constructor({ publicKey, secretKey, baseUrl = BASE_URL }: IPay100Config) {\n this.publicKey = publicKey;\n this.secretKey = secretKey;\n this.baseUrl = baseUrl;\n }\n\n /**\n * Creates a cryptographic signature for secure server-to-server communication\n *\n * @param payload - Request payload that needs to be signed\n * @returns Object containing current timestamp and HMAC SHA-256 signature\n * @throws Error if secret key is missing or invalid\n */\n private createSignature(payload: Record<string, unknown>): {\n timestamp: string;\n signature: string;\n } {\n const timestamp = Date.now().toString();\n\n // Extract the token part from the secret key if it's in the format\n // STATUS;TYPE;TOKEN (e.g., \"LIVE;SK;eyJhbGciOiJIUzI1...\")\n let signingSecret = this?.secretKey;\n\n if (this?.secretKey?.includes(\";\")) {\n const secretKeyParts = this.secretKey.split(\";\");\n if (secretKeyParts.length === 3) {\n // Use just the token part as the signing secret\n signingSecret = secretKeyParts[2];\n }\n }\n\n if (!signingSecret) {\n throw new Error(\"Secret key is required for signing\");\n }\n\n // Create signature using HMAC SHA-256\n const signature = crypto\n .createHmac(\"sha256\", signingSecret)\n .update(timestamp + JSON.stringify(payload))\n .digest(\"hex\");\n\n return { timestamp, signature };\n }\n\n /**\n * Constructs HTTP headers for API requests with optional authentication\n *\n * @param payload - Request payload used to generate security signature\n * @returns Object containing all necessary HTTP headers\n */\n private getHeaders(\n payload: Record<string, unknown> = {}\n ): Record<string, string> {\n // Generate authentication headers if secret key is available (server-side mode)\n if (this.secretKey) {\n const { timestamp, signature } = this.createSignature(payload);\n return {\n \"api-key\": this.publicKey,\n \"x-secret-key\": this.secretKey,\n \"x-timestamp\": timestamp,\n \"x-signature\": signature,\n \"Content-Type\": \"application/json\",\n };\n }\n\n // Basic headers for public API usage (client-side mode)\n return {\n \"api-key\": this.publicKey,\n \"Content-Type\": \"application/json\",\n };\n }\n\n /**\n * Verifies the status and details of a payment transaction\n *\n * @param transactionId - Unique identifier of the transaction to verify\n * @returns Promise resolving to verification result with transaction data\n * @throws PaymentVerificationError on network issues or invalid responses\n */\n verify = async (transactionId: string): Promise<IVerifyResponse> => {\n try {\n const payload = { transactionId };\n\n const response: AxiosResponse<IRawApiResponse> = await axios({\n method: \"POST\",\n url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,\n headers: this.getHeaders(payload),\n data: payload,\n });\n\n // Handle empty response\n if (!response.data) {\n return {\n status: \"error\",\n data: {},\n message:\n \"Something went wrong, be sure you supplied a valid payment id.\",\n };\n }\n\n // Handle string responses which indicate errors\n if (typeof response.data === \"string\") {\n if (response.data === \"Access Denied, Invalid KEY supplied\") {\n return {\n status: \"error\",\n data: {},\n message: \"Access Denied, Invalid KEY supplied\",\n };\n }\n\n if (response.data === \"invalid payment id supplied\") {\n return {\n status: \"error\",\n data: {},\n };\n }\n }\n\n // Validate and transform response data to ensure type safety\n const responseData = response.data;\n\n // Ensure the response data is an object that can be safely cast to ITransactionData\n const transactionData: ITransactionData =\n responseData && typeof responseData === \"object\"\n ? (responseData as ITransactionData)\n : {};\n\n // Return successful response with properly typed data\n return {\n status: \"success\",\n data: transactionData,\n };\n } catch (error) {\n // Handle Axios errors with detailed message\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n throw new PaymentVerificationError(\n axiosError.message ||\n \"Something went wrong, be sure you supplied a valid payment id.\"\n );\n }\n\n // Handle other errors with appropriate message\n throw new PaymentVerificationError(\n error instanceof Error ? error.message : \"An unknown error occurred\"\n );\n }\n };\n\n /**\n * Namespace for subaccount management operations\n * Provides methods to create and manage subaccounts\n */\n subaccounts = {\n /**\n * Creates a new subaccount within the platform\n *\n * @param data - Subaccount configuration including owner details and supported currencies\n * @returns Promise resolving to the created subaccount details\n * @throws Error if the request fails or returns invalid data\n */\n create: async (\n data: CreateSubAccountData\n ): Promise<CreateSubAccountResponse> => {\n // Make sure the networks are lowercase\n data.networks = data.networks.map((network) => network.toLowerCase());\n return this.request<CreateSubAccountResponse>(\n \"POST\",\n \"/api/v1/assets/subaccount/create\",\n data\n );\n },\n };\n\n /**\n * Namespace for currency conversion operations\n * Provides methods to calculate exchange rates and fees\n */\n conversion = {\n /**\n * Calculates a preview of currency conversion with rates and fees\n *\n * @param data - Conversion details including amount, source and target currencies\n * @returns Promise resolving to detailed conversion calculation\n * @throws Error if the request fails or returns invalid data\n */\n preview: async (\n data: CurrencyConversionPayload\n ): Promise<CurrencyConversionResult> => {\n return this.request<CurrencyConversionResult>(\n \"POST\",\n \"/api/v1/user/preview-convert-asset\",\n {\n amount: data.amount,\n to_symbol: data.toSymbol,\n from_symbol: data.fromSymbol,\n appId: data.appId,\n }\n );\n },\n };\n\n /**\n * Namespace for asset transfer operations\n * Provides methods to transfer assets, view history, and calculate fees\n */\n transfer = {\n /**\n * Transfer assets between wallets\n *\n * @param data - Transfer details including amount, currency, destination, and authentication\n * @returns Promise resolving to transfer confirmation with receipt and transaction ID\n * @throws Error if the transfer fails due to validation, insufficient funds, or other issues\n */\n executeTransfer: async (\n data: ITransferAssetData\n ): Promise<ITransferAssetResponse> => {\n return this.request<ITransferAssetResponse>(\n \"POST\",\n \"/api/v1/transfer/asset\",\n data\n );\n },\n\n /**\n * Get transfer history for the authenticated user\n *\n * @param params - Filtering and pagination parameters\n * @returns Promise resolving to paginated transfer history records\n * @throws Error if the request fails or authentication is invalid\n */\n getHistory: async (\n params: ITransferHistoryParams\n ): Promise<ITransferHistoryResponse> => {\n return this.request<ITransferHistoryResponse>(\n \"GET\",\n \"/api/v1/transfer/history\",\n params\n );\n },\n\n /**\n * Calculate transfer fees for a potential transaction\n *\n * @param params - Fee calculation parameters including currency and transfer type\n * @returns Promise resolving to detailed fee breakdown\n * @throws Error if the fee calculation fails or currency is not supported\n */\n calculateFee: async (\n params: ITransferFeeParams\n ): Promise<ITransferFeeResponse> => {\n return this.request<ITransferFeeResponse>(\n \"GET\",\n \"/api/v1/transfer/fee\",\n params\n );\n },\n };\n\n /**\n * Namespace for wallet operations\n * Provides methods to retrieve supported wallets\n */\n wallet = {\n /**\n * Get a list of supported wallets and their details\n *\n * @returns Promise resolving to an array of supported wallet configurations\n * @throws Error if the request fails or authentication is invalid\n */\n getSupportedWallets: async (): Promise<ISupportedWalletResponse> => {\n return this.request<ISupportedWalletResponse>(\n \"GET\",\n \"/api/v1/wallet/supported\"\n );\n },\n };\n\n /**\n * Generic method to make authenticated API requests to any endpoint\n *\n * @param method - HTTP method to use (GET, POST, PUT, DELETE)\n * @param endpoint - API endpoint path (will be appended to base URL)\n * @param data - Request payload or query parameters\n * @returns Promise resolving to the typed API response\n * @throws Error with detailed message on request failure\n */\n async request<T>(\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n endpoint: string,\n data: Record<string, unknown> = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n const headers = this.getHeaders(data);\n\n const response = await axios({\n method,\n url,\n headers,\n data: method !== \"GET\" ? data : undefined,\n params: method === \"GET\" ? data : undefined,\n });\n\n // Check if the response indicates an error despite a successful HTTP status\n if (\n response.data &&\n typeof response.data === \"object\" &&\n \"success\" in response.data\n ) {\n if ((response.data as { success?: boolean }).success === false) {\n // Extract error from the API's own error indication\n const errorMessage = this.extractErrorMessage(response.data);\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n }\n\n return response.data as T;\n } catch (error) {\n logger.error(error);\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n logger.error(axiosError?.response);\n\n // Extract error message from response data if available\n const errorMessage = axiosError.response?.data\n ? this.extractErrorMessage(axiosError.response.data)\n : axiosError.message;\n\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n\n // Rethrow original error if not an Axios error\n throw error;\n }\n }\n\n /**\n * Extracts error message from various response data structures\n *\n * @param data - The response data object which may contain error information\n * @returns The most specific error message available\n */\n private extractErrorMessage(data: unknown): string {\n // If data is a string, return it directly\n if (typeof data === \"string\") {\n return data;\n }\n\n // If data is not an object or is null, return a generic message\n if (typeof data !== \"object\" || data === null) {\n return \"Unknown error\";\n }\n\n // Handle different error structures\n const dataObj = data as Record<string, unknown>;\n\n // Direct error message in data.message\n if (\"message\" in dataObj && typeof dataObj.message === \"string\") {\n return dataObj.message;\n }\n\n // Error object with message property\n if (\"error\" in dataObj) {\n const error = dataObj.error;\n\n // String error\n if (typeof error === \"string\") {\n return error;\n }\n\n // Object error with message\n if (error && typeof error === \"object\") {\n const errorObj = error as Record<string, unknown>;\n\n if (\"message\" in errorObj && typeof errorObj.message === \"string\") {\n return errorObj.message;\n }\n\n // Try to get any useful information from the error object\n if (\"code\" in errorObj && typeof errorObj.code === \"string\") {\n return `Error code: ${errorObj.code}`;\n }\n }\n }\n\n // Look for error in the 'data' property\n if (\"data\" in dataObj && dataObj.data && typeof dataObj.data === \"object\") {\n const nestedData = dataObj.data as Record<string, unknown>;\n\n if (\"message\" in nestedData && typeof nestedData.message === \"string\") {\n return nestedData.message;\n }\n\n if (\n \"error\" in nestedData &&\n nestedData.error &&\n typeof nestedData.error === \"object\"\n ) {\n const nestedError = nestedData.error as Record<string, unknown>;\n if (\n \"message\" in nestedError &&\n typeof nestedError.message === \"string\"\n ) {\n return nestedError.message;\n }\n }\n }\n\n // If we have a statusText from the response, use that\n if (\"statusText\" in dataObj && typeof dataObj.statusText === \"string\") {\n return dataObj.statusText;\n }\n\n // Stringify the error if nothing else works\n try {\n return `Error details: ${JSON.stringify(dataObj)}`;\n } catch {\n return \"Unknown error occurred\";\n }\n }\n}\n\nexport * from \"./types\";\nexport * from \"./types/transfer\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAiD;AACjD,aAAwB;AAmBxB,oBAAuB;AAkCvB,IAAM,WAAW,QAAQ,IAAI,YAAY;AAMlC,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAIlD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,CAAC;AAAA,EACf;AACF;AAOO,IAAM,SAAN,MAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EASlB,YAAY,EAAE,WAAW,WAAW,UAAU,SAAS,GAAkB;AA+EzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAS,OAAO,kBAAoD;AAClE,UAAI;AACF,cAAM,UAAU,EAAE,cAAc;AAEhC,cAAM,WAA2C,UAAM,aAAAA,SAAM;AAAA,UAC3D,QAAQ;AAAA,UACR,KAAK,GAAG,KAAK,OAAO,8BAA8B,aAAa;AAAA,UAC/D,SAAS,KAAK,WAAW,OAAO;AAAA,UAChC,MAAM;AAAA,QACR,CAAC;AAGD,YAAI,CAAC,SAAS,MAAM;AAClB,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM,CAAC;AAAA,YACP,SACE;AAAA,UACJ;AAAA,QACF;AAGA,YAAI,OAAO,SAAS,SAAS,UAAU;AACr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ED
@@ -83,6 +83,7 @@ type CurrencyConversionResult = {
83
83
  };
84
84
 
85
85
  interface IWalletTransaction {
86
+ _id: string;
86
87
  accountId: string;
87
88
  subAccountId: string;
88
89
  appId: string;
@@ -142,7 +143,7 @@ interface ITransferHistoryParams extends Record<string, unknown> {
142
143
  /** Optional account address to filter transfers */
143
144
  addresses?: string[];
144
145
  /** Optional currency symbol to filter transfers */
145
- symbol?: string;
146
+ symbols?: string[];
146
147
  /** Page number for pagination */
147
148
  page?: number;
148
149
  /** Number of records per page */
@@ -177,6 +178,10 @@ interface ITransferHistoryResponse {
177
178
  limit: number;
178
179
  /** Total number of pages */
179
180
  pages: number;
181
+ /** Has next page */
182
+ hasNextPage: boolean;
183
+ /** Has previous page */
184
+ hasPreviousPage: boolean;
180
185
  };
181
186
  }
182
187
  /**
@@ -241,6 +246,17 @@ interface ISupportedWalletResponse {
241
246
  message: string;
242
247
  data: ISupportedWallet[];
243
248
  }
249
+ /**
250
+ * Standardized response interface for transaction verification
251
+ * @property status - Result status ('success' or 'error')
252
+ * @property data - Transaction details when successful, empty object on failure
253
+ * @property message - Optional response message, typically present on errors
254
+ */
255
+ interface IVerifyResponse {
256
+ status: "success" | "error";
257
+ data: ITransactionData | Record<string, never>;
258
+ message?: string;
259
+ }
244
260
 
245
261
  /**
246
262
  * Configuration interface for initializing the Pay100 SDK
@@ -260,17 +276,6 @@ interface IPay100Config {
260
276
  interface ITransactionData {
261
277
  [key: string]: unknown;
262
278
  }
263
- /**
264
- * Standardized response interface for transaction verification
265
- * @property status - Result status ('success' or 'error')
266
- * @property data - Transaction details when successful, empty object on failure
267
- * @property message - Optional response message, typically present on errors
268
- */
269
- interface IVerifyResponse {
270
- status: "success" | "error";
271
- data: ITransactionData | Record<string, never>;
272
- message?: string;
273
- }
274
279
  /**
275
280
  * Custom error class for payment verification failures
276
281
  * Provides consistent error structure for better error handling
@@ -407,4 +412,4 @@ declare class Pay100 {
407
412
  private extractErrorMessage;
408
413
  }
409
414
 
410
- export { type Account, type AccountDetails, type CreateSubAccountData, type CreateSubAccountResponse, type Crypto, type CurrencyConversionPayload, type CurrencyConversionResult, type ISupportedWallet, type ISupportedWalletResponse, type ITransferAssetData, type ITransferAssetResponse, type ITransferFeeParams, type ITransferFeeResponse, type ITransferHistoryItem, type ITransferHistoryParams, type ITransferHistoryResponse, type IWalletAccount, type IWalletBalance, type IWalletFee, type IWalletTransaction, type Key, type Network, Pay100, PaymentVerificationError };
415
+ export { type Account, type AccountDetails, type CreateSubAccountData, type CreateSubAccountResponse, type Crypto, type CurrencyConversionPayload, type CurrencyConversionResult, type ISupportedWallet, type ISupportedWalletResponse, type ITransactionData, type ITransferAssetData, type ITransferAssetResponse, type ITransferFeeParams, type ITransferFeeResponse, type ITransferHistoryItem, type ITransferHistoryParams, type ITransferHistoryResponse, type IVerifyResponse, type IWalletAccount, type IWalletBalance, type IWalletFee, type IWalletTransaction, type Key, type Network, Pay100, PaymentVerificationError };
package/dist/index.d.ts CHANGED
@@ -83,6 +83,7 @@ type CurrencyConversionResult = {
83
83
  };
84
84
 
85
85
  interface IWalletTransaction {
86
+ _id: string;
86
87
  accountId: string;
87
88
  subAccountId: string;
88
89
  appId: string;
@@ -142,7 +143,7 @@ interface ITransferHistoryParams extends Record<string, unknown> {
142
143
  /** Optional account address to filter transfers */
143
144
  addresses?: string[];
144
145
  /** Optional currency symbol to filter transfers */
145
- symbol?: string;
146
+ symbols?: string[];
146
147
  /** Page number for pagination */
147
148
  page?: number;
148
149
  /** Number of records per page */
@@ -177,6 +178,10 @@ interface ITransferHistoryResponse {
177
178
  limit: number;
178
179
  /** Total number of pages */
179
180
  pages: number;
181
+ /** Has next page */
182
+ hasNextPage: boolean;
183
+ /** Has previous page */
184
+ hasPreviousPage: boolean;
180
185
  };
181
186
  }
182
187
  /**
@@ -241,6 +246,17 @@ interface ISupportedWalletResponse {
241
246
  message: string;
242
247
  data: ISupportedWallet[];
243
248
  }
249
+ /**
250
+ * Standardized response interface for transaction verification
251
+ * @property status - Result status ('success' or 'error')
252
+ * @property data - Transaction details when successful, empty object on failure
253
+ * @property message - Optional response message, typically present on errors
254
+ */
255
+ interface IVerifyResponse {
256
+ status: "success" | "error";
257
+ data: ITransactionData | Record<string, never>;
258
+ message?: string;
259
+ }
244
260
 
245
261
  /**
246
262
  * Configuration interface for initializing the Pay100 SDK
@@ -260,17 +276,6 @@ interface IPay100Config {
260
276
  interface ITransactionData {
261
277
  [key: string]: unknown;
262
278
  }
263
- /**
264
- * Standardized response interface for transaction verification
265
- * @property status - Result status ('success' or 'error')
266
- * @property data - Transaction details when successful, empty object on failure
267
- * @property message - Optional response message, typically present on errors
268
- */
269
- interface IVerifyResponse {
270
- status: "success" | "error";
271
- data: ITransactionData | Record<string, never>;
272
- message?: string;
273
- }
274
279
  /**
275
280
  * Custom error class for payment verification failures
276
281
  * Provides consistent error structure for better error handling
@@ -407,4 +412,4 @@ declare class Pay100 {
407
412
  private extractErrorMessage;
408
413
  }
409
414
 
410
- export { type Account, type AccountDetails, type CreateSubAccountData, type CreateSubAccountResponse, type Crypto, type CurrencyConversionPayload, type CurrencyConversionResult, type ISupportedWallet, type ISupportedWalletResponse, type ITransferAssetData, type ITransferAssetResponse, type ITransferFeeParams, type ITransferFeeResponse, type ITransferHistoryItem, type ITransferHistoryParams, type ITransferHistoryResponse, type IWalletAccount, type IWalletBalance, type IWalletFee, type IWalletTransaction, type Key, type Network, Pay100, PaymentVerificationError };
415
+ export { type Account, type AccountDetails, type CreateSubAccountData, type CreateSubAccountResponse, type Crypto, type CurrencyConversionPayload, type CurrencyConversionResult, type ISupportedWallet, type ISupportedWalletResponse, type ITransactionData, type ITransferAssetData, type ITransferAssetResponse, type ITransferFeeParams, type ITransferFeeResponse, type ITransferHistoryItem, type ITransferHistoryParams, type ITransferHistoryResponse, type IVerifyResponse, type IWalletAccount, type IWalletBalance, type IWalletFee, type IWalletTransaction, type Key, type Network, Pay100, PaymentVerificationError };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// src/index.ts\n\nimport axios, { AxiosError, AxiosResponse } from \"axios\";\nimport * as crypto from \"crypto\";\nimport {\n CreateSubAccountData,\n CreateSubAccountResponse,\n} from \"./types/subAccount\";\nimport {\n CurrencyConversionPayload,\n CurrencyConversionResult,\n ISupportedWalletResponse,\n} from \"./types\";\nimport {\n ITransferAssetData,\n ITransferAssetResponse,\n ITransferHistoryParams,\n ITransferHistoryResponse,\n ITransferFeeParams,\n ITransferFeeResponse,\n} from \"./types/transfer\";\nimport { logger } from \"@untools/logger\";\n\n/**\n * Configuration interface for initializing the Pay100 SDK\n * @property publicKey - API public key required for all API calls\n * @property secretKey - Secret key used for server-side authentication and request signing\n * @property baseUrl - Optional API base URL, defaults to production endpoint\n */\ninterface IPay100Config {\n publicKey: string;\n secretKey?: string;\n baseUrl?: string;\n}\n\n/**\n * Interface representing transaction data returned from payment verification\n * Flexible structure to accommodate various transaction types and properties\n */\ninterface ITransactionData {\n [key: string]: unknown;\n}\n\n/**\n * Interface for raw API responses before processing\n * Provides a flexible structure while capturing common response elements\n */\ninterface IRawApiResponse {\n status?: string;\n message?: string;\n data?: unknown;\n [key: string]: unknown;\n}\n\n/**\n * Standardized response interface for transaction verification\n * @property status - Result status ('success' or 'error')\n * @property data - Transaction details when successful, empty object on failure\n * @property message - Optional response message, typically present on errors\n */\ninterface IVerifyResponse {\n status: \"success\" | \"error\";\n data: ITransactionData | Record<string, never>;\n message?: string;\n}\n\n// Default API endpoint if not otherwise specified\nconst BASE_URL = process.env.BASE_URL || \"https://api.100pay.co\";\n\n/**\n * Custom error class for payment verification failures\n * Provides consistent error structure for better error handling\n */\nexport class PaymentVerificationError extends Error {\n status: string;\n data: Record<string, never>;\n\n constructor(message: string) {\n super(message);\n this.name = \"PaymentVerificationError\";\n this.status = \"error\";\n this.data = {};\n }\n}\n\n/**\n * Main SDK class for interacting with the 100Pay payment platform\n * Provides methods for transaction verification, subaccount management,\n * currency conversion, and asset transfers\n */\nexport class Pay100 {\n private publicKey: string;\n private secretKey?: string;\n private baseUrl: string;\n\n /**\n * Initialize the Pay100 SDK\n * @param config - Configuration object containing API keys and optional base URL\n */\n constructor({ publicKey, secretKey, baseUrl = BASE_URL }: IPay100Config) {\n this.publicKey = publicKey;\n this.secretKey = secretKey;\n this.baseUrl = baseUrl;\n }\n\n /**\n * Creates a cryptographic signature for secure server-to-server communication\n *\n * @param payload - Request payload that needs to be signed\n * @returns Object containing current timestamp and HMAC SHA-256 signature\n * @throws Error if secret key is missing or invalid\n */\n private createSignature(payload: Record<string, unknown>): {\n timestamp: string;\n signature: string;\n } {\n const timestamp = Date.now().toString();\n\n // Extract the token part from the secret key if it's in the format\n // STATUS;TYPE;TOKEN (e.g., \"LIVE;SK;eyJhbGciOiJIUzI1...\")\n let signingSecret = this?.secretKey;\n\n if (this?.secretKey?.includes(\";\")) {\n const secretKeyParts = this.secretKey.split(\";\");\n if (secretKeyParts.length === 3) {\n // Use just the token part as the signing secret\n signingSecret = secretKeyParts[2];\n }\n }\n\n if (!signingSecret) {\n throw new Error(\"Secret key is required for signing\");\n }\n\n // Create signature using HMAC SHA-256\n const signature = crypto\n .createHmac(\"sha256\", signingSecret)\n .update(timestamp + JSON.stringify(payload))\n .digest(\"hex\");\n\n return { timestamp, signature };\n }\n\n /**\n * Constructs HTTP headers for API requests with optional authentication\n *\n * @param payload - Request payload used to generate security signature\n * @returns Object containing all necessary HTTP headers\n */\n private getHeaders(\n payload: Record<string, unknown> = {}\n ): Record<string, string> {\n // Generate authentication headers if secret key is available (server-side mode)\n if (this.secretKey) {\n const { timestamp, signature } = this.createSignature(payload);\n return {\n \"api-key\": this.publicKey,\n \"x-secret-key\": this.secretKey,\n \"x-timestamp\": timestamp,\n \"x-signature\": signature,\n \"Content-Type\": \"application/json\",\n };\n }\n\n // Basic headers for public API usage (client-side mode)\n return {\n \"api-key\": this.publicKey,\n \"Content-Type\": \"application/json\",\n };\n }\n\n /**\n * Verifies the status and details of a payment transaction\n *\n * @param transactionId - Unique identifier of the transaction to verify\n * @returns Promise resolving to verification result with transaction data\n * @throws PaymentVerificationError on network issues or invalid responses\n */\n verify = async (transactionId: string): Promise<IVerifyResponse> => {\n try {\n const payload = { transactionId };\n\n const response: AxiosResponse<IRawApiResponse> = await axios({\n method: \"POST\",\n url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,\n headers: this.getHeaders(payload),\n data: payload,\n });\n\n // Handle empty response\n if (!response.data) {\n return {\n status: \"error\",\n data: {},\n message:\n \"Something went wrong, be sure you supplied a valid payment id.\",\n };\n }\n\n // Handle string responses which indicate errors\n if (typeof response.data === \"string\") {\n if (response.data === \"Access Denied, Invalid KEY supplied\") {\n return {\n status: \"error\",\n data: {},\n message: \"Access Denied, Invalid KEY supplied\",\n };\n }\n\n if (response.data === \"invalid payment id supplied\") {\n return {\n status: \"error\",\n data: {},\n };\n }\n }\n\n // Validate and transform response data to ensure type safety\n const responseData = response.data;\n\n // Ensure the response data is an object that can be safely cast to ITransactionData\n const transactionData: ITransactionData =\n responseData && typeof responseData === \"object\"\n ? (responseData as ITransactionData)\n : {};\n\n // Return successful response with properly typed data\n return {\n status: \"success\",\n data: transactionData,\n };\n } catch (error) {\n // Handle Axios errors with detailed message\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n throw new PaymentVerificationError(\n axiosError.message ||\n \"Something went wrong, be sure you supplied a valid payment id.\"\n );\n }\n\n // Handle other errors with appropriate message\n throw new PaymentVerificationError(\n error instanceof Error ? error.message : \"An unknown error occurred\"\n );\n }\n };\n\n /**\n * Namespace for subaccount management operations\n * Provides methods to create and manage subaccounts\n */\n subaccounts = {\n /**\n * Creates a new subaccount within the platform\n *\n * @param data - Subaccount configuration including owner details and supported currencies\n * @returns Promise resolving to the created subaccount details\n * @throws Error if the request fails or returns invalid data\n */\n create: async (\n data: CreateSubAccountData\n ): Promise<CreateSubAccountResponse> => {\n // Make sure the networks are lowercase\n data.networks = data.networks.map((network) => network.toLowerCase());\n return this.request<CreateSubAccountResponse>(\n \"POST\",\n \"/api/v1/assets/subaccount/create\",\n data\n );\n },\n };\n\n /**\n * Namespace for currency conversion operations\n * Provides methods to calculate exchange rates and fees\n */\n conversion = {\n /**\n * Calculates a preview of currency conversion with rates and fees\n *\n * @param data - Conversion details including amount, source and target currencies\n * @returns Promise resolving to detailed conversion calculation\n * @throws Error if the request fails or returns invalid data\n */\n preview: async (\n data: CurrencyConversionPayload\n ): Promise<CurrencyConversionResult> => {\n return this.request<CurrencyConversionResult>(\n \"POST\",\n \"/api/v1/user/preview-convert-asset\",\n {\n amount: data.amount,\n to_symbol: data.toSymbol,\n from_symbol: data.fromSymbol,\n appId: data.appId,\n }\n );\n },\n };\n\n /**\n * Namespace for asset transfer operations\n * Provides methods to transfer assets, view history, and calculate fees\n */\n transfer = {\n /**\n * Transfer assets between wallets\n *\n * @param data - Transfer details including amount, currency, destination, and authentication\n * @returns Promise resolving to transfer confirmation with receipt and transaction ID\n * @throws Error if the transfer fails due to validation, insufficient funds, or other issues\n */\n executeTransfer: async (\n data: ITransferAssetData\n ): Promise<ITransferAssetResponse> => {\n return this.request<ITransferAssetResponse>(\n \"POST\",\n \"/api/v1/transfer/asset\",\n data\n );\n },\n\n /**\n * Get transfer history for the authenticated user\n *\n * @param params - Filtering and pagination parameters\n * @returns Promise resolving to paginated transfer history records\n * @throws Error if the request fails or authentication is invalid\n */\n getHistory: async (\n params: ITransferHistoryParams\n ): Promise<ITransferHistoryResponse> => {\n return this.request<ITransferHistoryResponse>(\n \"GET\",\n \"/api/v1/transfer/history\",\n params\n );\n },\n\n /**\n * Calculate transfer fees for a potential transaction\n *\n * @param params - Fee calculation parameters including currency and transfer type\n * @returns Promise resolving to detailed fee breakdown\n * @throws Error if the fee calculation fails or currency is not supported\n */\n calculateFee: async (\n params: ITransferFeeParams\n ): Promise<ITransferFeeResponse> => {\n return this.request<ITransferFeeResponse>(\n \"GET\",\n \"/api/v1/transfer/fee\",\n params\n );\n },\n };\n\n /**\n * Namespace for wallet operations\n * Provides methods to retrieve supported wallets\n */\n wallet = {\n /**\n * Get a list of supported wallets and their details\n *\n * @returns Promise resolving to an array of supported wallet configurations\n * @throws Error if the request fails or authentication is invalid\n */\n getSupportedWallets: async (): Promise<ISupportedWalletResponse> => {\n return this.request<ISupportedWalletResponse>(\n \"GET\",\n \"/api/v1/wallet/supported\"\n );\n },\n };\n\n /**\n * Generic method to make authenticated API requests to any endpoint\n *\n * @param method - HTTP method to use (GET, POST, PUT, DELETE)\n * @param endpoint - API endpoint path (will be appended to base URL)\n * @param data - Request payload or query parameters\n * @returns Promise resolving to the typed API response\n * @throws Error with detailed message on request failure\n */\n async request<T>(\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n endpoint: string,\n data: Record<string, unknown> = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n const headers = this.getHeaders(data);\n\n const response = await axios({\n method,\n url,\n headers,\n data: method !== \"GET\" ? data : undefined,\n params: method === \"GET\" ? data : undefined,\n });\n\n // Check if the response indicates an error despite a successful HTTP status\n if (\n response.data &&\n typeof response.data === \"object\" &&\n \"success\" in response.data\n ) {\n if ((response.data as { success?: boolean }).success === false) {\n // Extract error from the API's own error indication\n const errorMessage = this.extractErrorMessage(response.data);\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n }\n\n return response.data as T;\n } catch (error) {\n logger.error(error);\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n logger.error(axiosError?.response);\n\n // Extract error message from response data if available\n const errorMessage = axiosError.response?.data\n ? this.extractErrorMessage(axiosError.response.data)\n : axiosError.message;\n\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n\n // Rethrow original error if not an Axios error\n throw error;\n }\n }\n\n /**\n * Extracts error message from various response data structures\n *\n * @param data - The response data object which may contain error information\n * @returns The most specific error message available\n */\n private extractErrorMessage(data: unknown): string {\n // If data is a string, return it directly\n if (typeof data === \"string\") {\n return data;\n }\n\n // If data is not an object or is null, return a generic message\n if (typeof data !== \"object\" || data === null) {\n return \"Unknown error\";\n }\n\n // Handle different error structures\n const dataObj = data as Record<string, unknown>;\n\n // Direct error message in data.message\n if (\"message\" in dataObj && typeof dataObj.message === \"string\") {\n return dataObj.message;\n }\n\n // Error object with message property\n if (\"error\" in dataObj) {\n const error = dataObj.error;\n\n // String error\n if (typeof error === \"string\") {\n return error;\n }\n\n // Object error with message\n if (error && typeof error === \"object\") {\n const errorObj = error as Record<string, unknown>;\n\n if (\"message\" in errorObj && typeof errorObj.message === \"string\") {\n return errorObj.message;\n }\n\n // Try to get any useful information from the error object\n if (\"code\" in errorObj && typeof errorObj.code === \"string\") {\n return `Error code: ${errorObj.code}`;\n }\n }\n }\n\n // Look for error in the 'data' property\n if (\"data\" in dataObj && dataObj.data && typeof dataObj.data === \"object\") {\n const nestedData = dataObj.data as Record<string, unknown>;\n\n if (\"message\" in nestedData && typeof nestedData.message === \"string\") {\n return nestedData.message;\n }\n\n if (\n \"error\" in nestedData &&\n nestedData.error &&\n typeof nestedData.error === \"object\"\n ) {\n const nestedError = nestedData.error as Record<string, unknown>;\n if (\n \"message\" in nestedError &&\n typeof nestedError.message === \"string\"\n ) {\n return nestedError.message;\n }\n }\n }\n\n // If we have a statusText from the response, use that\n if (\"statusText\" in dataObj && typeof dataObj.statusText === \"string\") {\n return dataObj.statusText;\n }\n\n // Stringify the error if nothing else works\n try {\n return `Error details: ${JSON.stringify(dataObj)}`;\n } catch {\n return \"Unknown error occurred\";\n }\n }\n}\n\nexport * from \"./types\";\nexport * from \"./types/transfer\";\n"],"mappings":";AAEA,OAAO,WAA0C;AACjD,YAAY,YAAY;AAkBxB,SAAS,cAAc;AA8CvB,IAAM,WAAW,QAAQ,IAAI,YAAY;AAMlC,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAIlD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,C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QAAQ,QAAQ,OAAO,QAAQ,SAAS,UAAU;AACzE,YAAM,aAAa,QAAQ;AAE3B,UAAI,aAAa,cAAc,OAAO,WAAW,YAAY,UAAU;AACrE,eAAO,WAAW;AAAA,MACpB;AAEA,UACE,WAAW,cACX,WAAW,SACX,OAAO,WAAW,UAAU,UAC5B;AACA,cAAM,cAAc,WAAW;AAC/B,YACE,aAAa,eACb,OAAO,YAAY,YAAY,UAC/B;AACA,iBAAO,YAAY;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAGA,QAAI,gBAAgB,WAAW,OAAO,QAAQ,eAAe,UAAU;AACrE,aAAO,QAAQ;AAAA,IACjB;AAGA,QAAI;AACF,aAAO,kBAAkB,KAAK,UAAU,OAAO,CAAC;AAAA,IAClD,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// src/index.ts\n\nimport axios, { AxiosError, AxiosResponse } from \"axios\";\nimport * as crypto from \"crypto\";\nimport {\n CreateSubAccountData,\n CreateSubAccountResponse,\n} from \"./types/subAccount\";\nimport {\n CurrencyConversionPayload,\n CurrencyConversionResult,\n ISupportedWalletResponse,\n IVerifyResponse,\n} from \"./types\";\nimport {\n ITransferAssetData,\n ITransferAssetResponse,\n ITransferHistoryParams,\n ITransferHistoryResponse,\n ITransferFeeParams,\n ITransferFeeResponse,\n} from \"./types/transfer\";\nimport { logger } from \"@untools/logger\";\n\n/**\n * Configuration interface for initializing the Pay100 SDK\n * @property publicKey - API public key required for all API calls\n * @property secretKey - Secret key used for server-side authentication and request signing\n * @property baseUrl - Optional API base URL, defaults to production endpoint\n */\ninterface IPay100Config {\n publicKey: string;\n secretKey?: string;\n baseUrl?: string;\n}\n\n/**\n * Interface representing transaction data returned from payment verification\n * Flexible structure to accommodate various transaction types and properties\n */\nexport interface ITransactionData {\n [key: string]: unknown;\n}\n\n/**\n * Interface for raw API responses before processing\n * Provides a flexible structure while capturing common response elements\n */\ninterface IRawApiResponse {\n status?: string;\n message?: string;\n data?: unknown;\n [key: string]: unknown;\n}\n\n// Default API endpoint if not otherwise specified\nconst BASE_URL = process.env.BASE_URL || \"https://api.100pay.co\";\n\n/**\n * Custom error class for payment verification failures\n * Provides consistent error structure for better error handling\n */\nexport class PaymentVerificationError extends Error {\n status: string;\n data: Record<string, never>;\n\n constructor(message: string) {\n super(message);\n this.name = \"PaymentVerificationError\";\n this.status = \"error\";\n this.data = {};\n }\n}\n\n/**\n * Main SDK class for interacting with the 100Pay payment platform\n * Provides methods for transaction verification, subaccount management,\n * currency conversion, and asset transfers\n */\nexport class Pay100 {\n private publicKey: string;\n private secretKey?: string;\n private baseUrl: string;\n\n /**\n * Initialize the Pay100 SDK\n * @param config - Configuration object containing API keys and optional base URL\n */\n constructor({ publicKey, secretKey, baseUrl = BASE_URL }: IPay100Config) {\n this.publicKey = publicKey;\n this.secretKey = secretKey;\n this.baseUrl = baseUrl;\n }\n\n /**\n * Creates a cryptographic signature for secure server-to-server communication\n *\n * @param payload - Request payload that needs to be signed\n * @returns Object containing current timestamp and HMAC SHA-256 signature\n * @throws Error if secret key is missing or invalid\n */\n private createSignature(payload: Record<string, unknown>): {\n timestamp: string;\n signature: string;\n } {\n const timestamp = Date.now().toString();\n\n // Extract the token part from the secret key if it's in the format\n // STATUS;TYPE;TOKEN (e.g., \"LIVE;SK;eyJhbGciOiJIUzI1...\")\n let signingSecret = this?.secretKey;\n\n if (this?.secretKey?.includes(\";\")) {\n const secretKeyParts = this.secretKey.split(\";\");\n if (secretKeyParts.length === 3) {\n // Use just the token part as the signing secret\n signingSecret = secretKeyParts[2];\n }\n }\n\n if (!signingSecret) {\n throw new Error(\"Secret key is required for signing\");\n }\n\n // Create signature using HMAC SHA-256\n const signature = crypto\n .createHmac(\"sha256\", signingSecret)\n .update(timestamp + JSON.stringify(payload))\n .digest(\"hex\");\n\n return { timestamp, signature };\n }\n\n /**\n * Constructs HTTP headers for API requests with optional authentication\n *\n * @param payload - Request payload used to generate security signature\n * @returns Object containing all necessary HTTP headers\n */\n private getHeaders(\n payload: Record<string, unknown> = {}\n ): Record<string, string> {\n // Generate authentication headers if secret key is available (server-side mode)\n if (this.secretKey) {\n const { timestamp, signature } = this.createSignature(payload);\n return {\n \"api-key\": this.publicKey,\n \"x-secret-key\": this.secretKey,\n \"x-timestamp\": timestamp,\n \"x-signature\": signature,\n \"Content-Type\": \"application/json\",\n };\n }\n\n // Basic headers for public API usage (client-side mode)\n return {\n \"api-key\": this.publicKey,\n \"Content-Type\": \"application/json\",\n };\n }\n\n /**\n * Verifies the status and details of a payment transaction\n *\n * @param transactionId - Unique identifier of the transaction to verify\n * @returns Promise resolving to verification result with transaction data\n * @throws PaymentVerificationError on network issues or invalid responses\n */\n verify = async (transactionId: string): Promise<IVerifyResponse> => {\n try {\n const payload = { transactionId };\n\n const response: AxiosResponse<IRawApiResponse> = await axios({\n method: \"POST\",\n url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,\n headers: this.getHeaders(payload),\n data: payload,\n });\n\n // Handle empty response\n if (!response.data) {\n return {\n status: \"error\",\n data: {},\n message:\n \"Something went wrong, be sure you supplied a valid payment id.\",\n };\n }\n\n // Handle string responses which indicate errors\n if (typeof response.data === \"string\") {\n if (response.data === \"Access Denied, Invalid KEY supplied\") {\n return {\n status: \"error\",\n data: {},\n message: \"Access Denied, Invalid KEY supplied\",\n };\n }\n\n if (response.data === \"invalid payment id supplied\") {\n return {\n status: \"error\",\n data: {},\n };\n }\n }\n\n // Validate and transform response data to ensure type safety\n const responseData = response.data;\n\n // Ensure the response data is an object that can be safely cast to ITransactionData\n const transactionData: ITransactionData =\n responseData && typeof responseData === \"object\"\n ? (responseData as ITransactionData)\n : {};\n\n // Return successful response with properly typed data\n return {\n status: \"success\",\n data: transactionData,\n };\n } catch (error) {\n // Handle Axios errors with detailed message\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n throw new PaymentVerificationError(\n axiosError.message ||\n \"Something went wrong, be sure you supplied a valid payment id.\"\n );\n }\n\n // Handle other errors with appropriate message\n throw new PaymentVerificationError(\n error instanceof Error ? error.message : \"An unknown error occurred\"\n );\n }\n };\n\n /**\n * Namespace for subaccount management operations\n * Provides methods to create and manage subaccounts\n */\n subaccounts = {\n /**\n * Creates a new subaccount within the platform\n *\n * @param data - Subaccount configuration including owner details and supported currencies\n * @returns Promise resolving to the created subaccount details\n * @throws Error if the request fails or returns invalid data\n */\n create: async (\n data: CreateSubAccountData\n ): Promise<CreateSubAccountResponse> => {\n // Make sure the networks are lowercase\n data.networks = data.networks.map((network) => network.toLowerCase());\n return this.request<CreateSubAccountResponse>(\n \"POST\",\n \"/api/v1/assets/subaccount/create\",\n data\n );\n },\n };\n\n /**\n * Namespace for currency conversion operations\n * Provides methods to calculate exchange rates and fees\n */\n conversion = {\n /**\n * Calculates a preview of currency conversion with rates and fees\n *\n * @param data - Conversion details including amount, source and target currencies\n * @returns Promise resolving to detailed conversion calculation\n * @throws Error if the request fails or returns invalid data\n */\n preview: async (\n data: CurrencyConversionPayload\n ): Promise<CurrencyConversionResult> => {\n return this.request<CurrencyConversionResult>(\n \"POST\",\n \"/api/v1/user/preview-convert-asset\",\n {\n amount: data.amount,\n to_symbol: data.toSymbol,\n from_symbol: data.fromSymbol,\n appId: data.appId,\n }\n );\n },\n };\n\n /**\n * Namespace for asset transfer operations\n * Provides methods to transfer assets, view history, and calculate fees\n */\n transfer = {\n /**\n * Transfer assets between wallets\n *\n * @param data - Transfer details including amount, currency, destination, and authentication\n * @returns Promise resolving to transfer confirmation with receipt and transaction ID\n * @throws Error if the transfer fails due to validation, insufficient funds, or other issues\n */\n executeTransfer: async (\n data: ITransferAssetData\n ): Promise<ITransferAssetResponse> => {\n return this.request<ITransferAssetResponse>(\n \"POST\",\n \"/api/v1/transfer/asset\",\n data\n );\n },\n\n /**\n * Get transfer history for the authenticated user\n *\n * @param params - Filtering and pagination parameters\n * @returns Promise resolving to paginated transfer history records\n * @throws Error if the request fails or authentication is invalid\n */\n getHistory: async (\n params: ITransferHistoryParams\n ): Promise<ITransferHistoryResponse> => {\n return this.request<ITransferHistoryResponse>(\n \"GET\",\n \"/api/v1/transfer/history\",\n params\n );\n },\n\n /**\n * Calculate transfer fees for a potential transaction\n *\n * @param params - Fee calculation parameters including currency and transfer type\n * @returns Promise resolving to detailed fee breakdown\n * @throws Error if the fee calculation fails or currency is not supported\n */\n calculateFee: async (\n params: ITransferFeeParams\n ): Promise<ITransferFeeResponse> => {\n return this.request<ITransferFeeResponse>(\n \"GET\",\n \"/api/v1/transfer/fee\",\n params\n );\n },\n };\n\n /**\n * Namespace for wallet operations\n * Provides methods to retrieve supported wallets\n */\n wallet = {\n /**\n * Get a list of supported wallets and their details\n *\n * @returns Promise resolving to an array of supported wallet configurations\n * @throws Error if the request fails or authentication is invalid\n */\n getSupportedWallets: async (): Promise<ISupportedWalletResponse> => {\n return this.request<ISupportedWalletResponse>(\n \"GET\",\n \"/api/v1/wallet/supported\"\n );\n },\n };\n\n /**\n * Generic method to make authenticated API requests to any endpoint\n *\n * @param method - HTTP method to use (GET, POST, PUT, DELETE)\n * @param endpoint - API endpoint path (will be appended to base URL)\n * @param data - Request payload or query parameters\n * @returns Promise resolving to the typed API response\n * @throws Error with detailed message on request failure\n */\n async request<T>(\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n endpoint: string,\n data: Record<string, unknown> = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n const headers = this.getHeaders(data);\n\n const response = await axios({\n method,\n url,\n headers,\n data: method !== \"GET\" ? data : undefined,\n params: method === \"GET\" ? data : undefined,\n });\n\n // Check if the response indicates an error despite a successful HTTP status\n if (\n response.data &&\n typeof response.data === \"object\" &&\n \"success\" in response.data\n ) {\n if ((response.data as { success?: boolean }).success === false) {\n // Extract error from the API's own error indication\n const errorMessage = this.extractErrorMessage(response.data);\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n }\n\n return response.data as T;\n } catch (error) {\n logger.error(error);\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n logger.error(axiosError?.response);\n\n // Extract error message from response data if available\n const errorMessage = axiosError.response?.data\n ? this.extractErrorMessage(axiosError.response.data)\n : axiosError.message;\n\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n\n // Rethrow original error if not an Axios error\n throw error;\n }\n }\n\n /**\n * Extracts error message from various response data structures\n *\n * @param data - The response data object which may contain error information\n * @returns The most specific error message available\n */\n private extractErrorMessage(data: unknown): string {\n // If data is a string, return it directly\n if (typeof data === \"string\") {\n return data;\n }\n\n // If data is not an object or is null, return a generic message\n if (typeof data !== \"object\" || data === null) {\n return \"Unknown error\";\n }\n\n // Handle different error structures\n const dataObj = data as Record<string, unknown>;\n\n // Direct error message in data.message\n if (\"message\" in dataObj && typeof dataObj.message === \"string\") {\n return dataObj.message;\n }\n\n // Error object with message property\n if (\"error\" in dataObj) {\n const error = dataObj.error;\n\n // String error\n if (typeof error === \"string\") {\n return error;\n }\n\n // Object error with message\n if (error && typeof error === \"object\") {\n const errorObj = error as Record<string, unknown>;\n\n if (\"message\" in errorObj && typeof errorObj.message === \"string\") {\n return errorObj.message;\n }\n\n // Try to get any useful information from the error object\n if (\"code\" in errorObj && typeof errorObj.code === \"string\") {\n return `Error code: ${errorObj.code}`;\n }\n }\n }\n\n // Look for error in the 'data' property\n if (\"data\" in dataObj && dataObj.data && typeof dataObj.data === \"object\") {\n const nestedData = dataObj.data as Record<string, unknown>;\n\n if (\"message\" in nestedData && typeof nestedData.message === \"string\") {\n return nestedData.message;\n }\n\n if (\n \"error\" in nestedData &&\n nestedData.error &&\n typeof nestedData.error === \"object\"\n ) {\n const nestedError = nestedData.error as Record<string, unknown>;\n if (\n \"message\" in nestedError &&\n typeof nestedError.message === \"string\"\n ) {\n return nestedError.message;\n }\n }\n }\n\n // If we have a statusText from the response, use that\n if (\"statusText\" in dataObj && typeof dataObj.statusText === \"string\") {\n return dataObj.statusText;\n }\n\n // Stringify the error if nothing else works\n try {\n return `Error details: ${JSON.stringify(dataObj)}`;\n } catch {\n return \"Unknown error occurred\";\n }\n }\n}\n\nexport * from \"./types\";\nexport * from \"./types/transfer\";\n"],"mappings":";AAEA,OAAO,WAA0C;AACjD,YAAY,YAAY;AAmBxB,SAAS,cAAc;AAkCvB,IAAM,WAAW,QAAQ,IAAI,YAAY;AAMlC,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAIlD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,CAAC;AAAA,EACf;AACF;AAOO,IAAM,SAAN,MAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EASlB,YAAY,EAAE,WAAW,WAAW,UAAU,SAAS,GAAkB;AA+EzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAS,OAAO,kBAAoD;AAClE,UAAI;AACF,cAAM,UAAU,EAAE,cAAc;AAEhC,cAAM,WAA2C,MAAM,MAAM;AAAA,UAC3D,QAAQ;AAAA,UACR,KAAK,GAAG,KAAK,OAAO,8BAA8B,aAAa;AAAA,UAC/D,SAAS,KAAK,WAAW,OAAO;AAAA,UAChC,MAAM;AAAA,QACR,CAAC;AAGD,YAAI,CAAC,SAAS,MAAM;AAClB,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM,CAAC;AAAA,YACP,SACE;AAAA,UACJ;AAAA,QACF;AAGA,YAAI,OAAO,SAAS,SAAS,UAAU;AACrC,cAAI,SAAS,SAAS,uCAAuC;AAC3D,mBAAO;AAAA,cACL,QAAQ;AAAA,cACR,MAAM,CAAC;AAAA,cACP,SAAS;AAAA,YACX;AAAA,UACF;AAEA,cAAI,SAAS,SAAS,+BAA+B;AACnD,mBAAO;AAAA,cACL,QAAQ;AAAA,cACR,MAAM,CAAC;AAAA,YACT;AAAA,UACF;AAAA,QACF;AAGA,cAAM,eAAe,SAAS;AAG9B,cAAM,kBACJ,g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AI,WAAW,SAAS;AACtB,YAAM,QAAQ,QAAQ;AAGtB,UAAI,OAAO,UAAU,UAAU;AAC7B,eAAO;AAAA,MACT;AAGA,UAAI,SAAS,OAAO,UAAU,UAAU;AACtC,cAAM,WAAW;AAEjB,YAAI,aAAa,YAAY,OAAO,SAAS,YAAY,UAAU;AACjE,iBAAO,SAAS;AAAA,QAClB;AAGA,YAAI,UAAU,YAAY,OAAO,SAAS,SAAS,UAAU;AAC3D,iBAAO,eAAe,SAAS,IAAI;AAAA,QACrC;AAAA,MACF;AAAA,IACF;AAGA,QAAI,UAAU,WAAW,QAAQ,QAAQ,OAAO,QAAQ,SAAS,UAAU;AACzE,YAAM,aAAa,QAAQ;AAE3B,UAAI,aAAa,cAAc,OAAO,WAAW,YAAY,UAAU;AACrE,eAAO,WAAW;AAAA,MACpB;AAEA,UACE,WAAW,cACX,WAAW,SACX,OAAO,WAAW,UAAU,UAC5B;AACA,cAAM,cAAc,WAAW;AAC/B,YACE,aAAa,eACb,OAAO,YAAY,YAAY,UAC/B;AACA,iBAAO,YAAY;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAGA,QAAI,gBAAgB,WAAW,OAAO,QAAQ,eAAe,UAAU;AACrE,aAAO,QAAQ;AAAA,IACjB;AAGA,QAAI;AACF,aAAO,kBAAkB,KAAK,UAAU,OAAO,CAAC;AAAA,IAClD,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@100pay-hq/100pay.js",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "100Pay.js is the official Nodejs API wrapper SDK that lets you easily verify crypto payments, run bulk payout, transfer assets and many more.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",