@p2pdotme/sdk 1.1.0 → 1.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/qr-parsers/index.ts","../src/qr-parsers/errors.ts","../src/country/currency.ts","../src/country/currencies/ars.ts","../src/country/currencies/brl.ts","../src/country/currencies/cop.ts","../src/country/currencies/eur.ts","../src/country/currencies/idr.ts","../src/country/currencies/inr.ts","../src/country/currencies/mex.ts","../src/country/currencies/ngn.ts","../src/country/currencies/usd.ts","../src/country/currencies/ven.ts","../src/country/countries.ts","../src/qr-parsers/types.ts","../src/qr-parsers/utils/crc16.ts","../src/qr-parsers/utils/tlv.ts","../src/qr-parsers/parsers/ars.ts","../src/qr-parsers/parsers/brl.ts","../src/qr-parsers/utils/amount.ts","../src/qr-parsers/parsers/idr.ts","../src/qr-parsers/parsers/inr.ts","../src/qr-parsers/parsers/ven.ts","../src/qr-parsers/parse-qr.ts"],"sourcesContent":["export { QRParserError, type QRParserErrorCode } from \"./errors\";\nexport { parseQR } from \"./parse-qr\";\nexport type {\n\tParsedQR,\n\tParseQRParams,\n\tParseResult,\n\tSupportedCurrency,\n} from \"./types\";\n","export type QRParserErrorCode =\n\t| \"INVALID_QR\"\n\t| \"INVALID_CURRENCY\"\n\t| \"INVALID_AMOUNT\"\n\t| \"FETCH_FAILED\";\n\nexport class QRParserError extends Error {\n\treadonly code: QRParserErrorCode;\n\treadonly cause?: unknown;\n\treadonly context?: Record<string, unknown>;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\tcode: QRParserErrorCode;\n\t\t\tcause?: unknown;\n\t\t\tcontext?: Record<string, unknown>;\n\t\t},\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"QRParserError\";\n\t\tthis.code = options.code;\n\t\tthis.cause = options.cause;\n\t\tthis.context = options.context;\n\t}\n}\n","/**\n * All supported currency symbols. Single source of truth for the SDK.\n *\n * Lives alongside the country metadata so that adding a currency is a\n * single-folder operation: drop a new file in `currencies/<code>.ts`, add it\n * to this map, and both `COUNTRY_OPTIONS` and `ZodCurrencySchema` pick it up.\n */\nexport const CURRENCY = {\n\tIDR: \"IDR\",\n\tINR: \"INR\",\n\tBRL: \"BRL\",\n\tARS: \"ARS\",\n\tMEX: \"MEX\",\n\tVEN: \"VEN\",\n\tEUR: \"EUR\",\n\tNGN: \"NGN\",\n\tUSD: \"USD\",\n\tCOP: \"COP\",\n} as const;\n\n/** Union of supported currency codes. */\nexport type CurrencyCode = (typeof CURRENCY)[keyof typeof CURRENCY];\n\n/**\n * Tuple form of the currency codes — used by `z.enum(...)` in the shared\n * validation layer. Narrow tuple type required by Zod.\n */\nexport const CURRENCY_CODES = Object.values(CURRENCY) as [CurrencyCode, ...CurrencyCode[]];\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const ARS_PLACEHOLDER = \"juan.perez\";\nexport const ARS_VALIDATION_ERROR =\n\t\"Please enter a valid CBU/CVU (22 digits) or Alias (6-20 characters)\";\n\n/** Validates CBU (Clave Bancaria Uniforme) — Argentine banking key, 22 digits with checksums. */\nfunction validateCBU(cbu: string): boolean {\n\tif (cbu.length !== 22) return false;\n\tif (/^(\\d)\\1{21}$/.test(cbu)) return false;\n\n\tconst bankCode = cbu.substring(0, 7);\n\tconst bankCheckDigit = parseInt(cbu[7], 10);\n\tlet sum = 0;\n\tconst weights = [7, 1, 3, 9, 7, 1, 3];\n\tfor (let i = 0; i < 7; i++) {\n\t\tsum += parseInt(bankCode[i], 10) * weights[i];\n\t}\n\tconst calculatedBankCheck = (10 - (sum % 10)) % 10;\n\tif (bankCheckDigit !== calculatedBankCheck) return false;\n\n\tconst accountNumber = cbu.substring(8, 21);\n\tconst accountCheckDigit = parseInt(cbu[21], 10);\n\tsum = 0;\n\tconst accountWeights = [3, 9, 7, 1, 3, 9, 7, 1, 3, 9, 7, 1, 3];\n\tfor (let i = 0; i < 13; i++) {\n\t\tsum += parseInt(accountNumber[i], 10) * accountWeights[i];\n\t}\n\tconst calculatedAccountCheck = (10 - (sum % 10)) % 10;\n\tif (accountCheckDigit !== calculatedAccountCheck) return false;\n\n\treturn true;\n}\n\n/**\n * Validates Argentine payment IDs (CBU, CVU, or Alias).\n * CBU/CVU: 22 digits with checksum. Alias: 6-20 alphanumeric characters.\n */\nexport function validateArgentinePaymentId(paymentId: string): boolean {\n\tif (!paymentId || paymentId.trim().length === 0) return false;\n\n\tconst trimmedPaymentId = paymentId.trim();\n\n\tif (/^\\d{22}$/.test(trimmedPaymentId)) return validateCBU(trimmedPaymentId);\n\tif (/^[a-zA-Z0-9.\\-_]{6,20}$/.test(trimmedPaymentId)) return true;\n\n\treturn false;\n}\n\n/** Payment ID field configuration for ARS (Argentina, ALIAS). */\nexport const ARS_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"alias\",\n\t\tlabel: \"ALIAS_ID\",\n\t\tplaceholder: ARS_PLACEHOLDER,\n\t\tdisplayLabel: \"Alias\",\n\t\tvalidate: validateArgentinePaymentId,\n\t\tvalidationErrorMessage: ARS_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Argentina (ARS). */\nexport const ARS_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Argentina\",\n\tcurrency: CURRENCY.ARS,\n\tsymbolNative: \"$\",\n\tlocale: \"es-AR\",\n\tpaymentMethod: \"ALIAS\",\n\tpaymentAddressName: \"ALIAS_ID\",\n\ttimezone: \"America/Argentina/Buenos_Aires\",\n\ttimezone_name: \"ART\",\n\tflag: \"🇦🇷\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1e6-1f1f7.png\",\n\tphoneCode: \"+54\",\n\ttelegramSupportChannel: \"https://t.me/p2pmeargentina\",\n\ttwitterUsername: \"p2pmeargentina\",\n\tsmsCountryCodes: [\"AR\"],\n\tprecision: 2,\n\tisAlpha: false,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const BRL_PLACEHOLDER = \"Chave pix ou pix copia e cola\";\nexport const BRL_VALIDATION_ERROR = \"Please enter a valid PIX ID\";\n\n/** Validates CPF (Brazilian tax ID for individuals). */\nfunction validateCPF(cpf: string): boolean {\n\tif (cpf.length !== 11) return false;\n\tif (/^(\\d)\\1{10}$/.test(cpf)) return false;\n\n\tlet sum = 0;\n\tfor (let i = 0; i < 9; i++) {\n\t\tsum += parseInt(cpf[i], 10) * (10 - i);\n\t}\n\tlet remainder = sum % 11;\n\tconst firstDigit = remainder < 2 ? 0 : 11 - remainder;\n\tif (parseInt(cpf[9], 10) !== firstDigit) return false;\n\n\tsum = 0;\n\tfor (let i = 0; i < 10; i++) {\n\t\tsum += parseInt(cpf[i], 10) * (11 - i);\n\t}\n\tremainder = sum % 11;\n\tconst secondDigit = remainder < 2 ? 0 : 11 - remainder;\n\treturn parseInt(cpf[10], 10) === secondDigit;\n}\n\n/** Validates CNPJ (Brazilian tax ID for companies). */\nfunction validateCNPJ(cnpj: string): boolean {\n\tif (cnpj.length !== 14) return false;\n\tif (/^(\\d)\\1{13}$/.test(cnpj)) return false;\n\n\tlet sum = 0;\n\tconst weights1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];\n\tfor (let i = 0; i < 12; i++) {\n\t\tsum += parseInt(cnpj[i], 10) * weights1[i];\n\t}\n\tlet remainder = sum % 11;\n\tconst firstDigit = remainder < 2 ? 0 : 11 - remainder;\n\tif (parseInt(cnpj[12], 10) !== firstDigit) return false;\n\n\tsum = 0;\n\tconst weights2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];\n\tfor (let i = 0; i < 13; i++) {\n\t\tsum += parseInt(cnpj[i], 10) * weights2[i];\n\t}\n\tremainder = sum % 11;\n\tconst secondDigit = remainder < 2 ? 0 : 11 - remainder;\n\treturn parseInt(cnpj[13], 10) === secondDigit;\n}\n\n/**\n * Validates PIX ID format.\n * PIX can be: CPF (11 digits), CNPJ (14 digits), email, phone (10–11 digits or E.164),\n * random key (UUID), or a PIX \"copia e cola\" EMV QR payload (starts with 000201).\n */\nexport function validatePIXId(pixId: string): boolean {\n\tif (!pixId || pixId.trim().length === 0) return false;\n\n\tconst trimmedPixId = pixId.trim();\n\n\t// PIX \"copia e cola\" — EMV QR code payload\n\tif (/^000201/.test(trimmedPixId)) return true;\n\n\t// 11 digits: valid CPF or Brazilian mobile phone key (DDD 11–99 + digit 9 + 8 digits)\n\tif (/^\\d{11}$/.test(trimmedPixId))\n\t\treturn validateCPF(trimmedPixId) || /^[1-9][1-9]9\\d{8}$/.test(trimmedPixId);\n\tif (/^\\d{14}$/.test(trimmedPixId)) return validateCNPJ(trimmedPixId);\n\tif (/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(trimmedPixId)) return true;\n\t// Phone key: 10–11 digits (with or without country code prefix)\n\tif (/^\\d{10,11}$/.test(trimmedPixId)) return true;\n\tif (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(trimmedPixId))\n\t\treturn true;\n\n\treturn false;\n}\n\n/** Payment ID field configuration for BRL (Brazil, PIX). */\nexport const BRL_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"pix\",\n\t\tlabel: \"PIX_ID\",\n\t\tplaceholder: BRL_PLACEHOLDER,\n\t\tdisplayLabel: \"PIX ID\",\n\t\tvalidate: validatePIXId,\n\t\tvalidationErrorMessage: BRL_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Brazil (BRL). */\nexport const BRL_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Brazil\",\n\tcurrency: CURRENCY.BRL,\n\tsymbolNative: \"R$\",\n\tlocale: \"pt-BR\",\n\tpaymentMethod: \"PIX\",\n\tpaymentAddressName: \"PIX_ID\",\n\ttimezone: \"America/Sao_Paulo\",\n\ttimezone_name: \"BRT\",\n\tflag: \"🇧🇷\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1e7-1f1f7.png\",\n\tphoneCode: \"+55\",\n\ttelegramSupportChannel: \"https://t.me/p2pmebrasil\",\n\ttwitterUsername: \"p2pmebrasil\",\n\tsmsCountryCodes: [\"BR\"],\n\tprecision: 2,\n\tisAlpha: false,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const COP_PLACEHOLDER = \"juan.perez@nequi.com.co\";\nexport const COP_VALIDATION_ERROR =\n\t\"Please enter a valid Nequi or Daviplata ID (e.g., 3001234567 or email)\";\n\n/**\n * Validates Colombian payment ID for Nequi or Daviplata.\n * Accepts a 10-digit phone number starting with 3, or a valid email address.\n */\nexport function validateColombianPaymentId(paymentId: string): boolean {\n\tif (!paymentId || paymentId.trim().length === 0) return false;\n\tconst trimmed = paymentId.trim();\n\tif (/^3\\d{9}$/.test(trimmed)) return true;\n\tif (/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(trimmed)) return true;\n\treturn false;\n}\n\n/** Payment ID field configuration for COP (Colombia, Transferencia). */\nexport const COP_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"alias\",\n\t\tlabel: \"ALIAS_TRANSFERENCIA\",\n\t\tplaceholder: COP_PLACEHOLDER,\n\t\tdisplayLabel: \"Nequi / Daviplata\",\n\t\tvalidate: validateColombianPaymentId,\n\t\tvalidationErrorMessage: COP_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Colombia (COP). */\nexport const COP_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Colombia\",\n\tcurrency: CURRENCY.COP,\n\tsymbolNative: \"$\",\n\tlocale: \"es-CO\",\n\tpaymentMethod: \"TRANSFERENCIA\",\n\tpaymentAddressName: \"ALIAS_TRANSFERENCIA\",\n\ttimezone: \"America/Bogota\",\n\ttimezone_name: \"COT\",\n\tflag: \"🇨🇴\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1e8-1f1f4.png\",\n\tphoneCode: \"+57\",\n\ttelegramSupportChannel: \"https://t.me/p2pmeColombia\",\n\ttwitterUsername: \"p2pmeColombia\",\n\tsmsCountryCodes: [\"CO\"],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [\"PAY\"],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const EUR_PLACEHOLDER = \"@username or email\";\nexport const EUR_VALIDATION_ERROR = \"Please enter a valid Revolut ID (username, email, or phone)\";\n\n/**\n * Validates Revolut ID (username, email, or phone number).\n */\nexport function validateRevolutId(revolutId: string): boolean {\n\tif (!revolutId || revolutId.trim().length === 0) return false;\n\n\tconst trimmed = revolutId.trim();\n\n\tif (/^@?[a-zA-Z0-9._-]{3,30}$/.test(trimmed)) return true;\n\tif (/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(trimmed)) return true;\n\tif (/^\\+?\\d{7,15}$/.test(trimmed)) return true;\n\n\treturn false;\n}\n\n/** Payment ID field configuration for EUR (Revolut EUR). */\nexport const EUR_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"revolut\",\n\t\tlabel: \"REVOLUT_ID\",\n\t\tplaceholder: EUR_PLACEHOLDER,\n\t\tdisplayLabel: \"Revolut ID\",\n\t\tvalidate: validateRevolutId,\n\t\tvalidationErrorMessage: EUR_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Revolut EUR. */\nexport const EUR_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Revolut EUR\",\n\tcurrency: CURRENCY.EUR,\n\tsymbolNative: \"€\",\n\tlocale: \"de-DE\",\n\tpaymentMethod: \"REVOLUT\",\n\tpaymentAddressName: \"REVOLUT_ID\",\n\ttimezone: \"Europe/Berlin\",\n\ttimezone_name: \"CET\",\n\tflag: \"\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f310.png\",\n\tphoneCode: \"\",\n\ttelegramSupportChannel: \"https://t.me/P2Pdotme\",\n\ttwitterUsername: \"P2Pdotme\",\n\tsmsCountryCodes: [],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [\"PAY\"],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const IDR_PLACEHOLDER = \"8123456789\";\nexport const IDR_VALIDATION_ERROR =\n\t\"Please enter a valid Indonesian phone number (e.g., 8123456789)\";\n\n/**\n * Validates Indonesian phone number.\n * Validates just the number part (9-12 digits).\n */\nexport function validateIndonesianPhoneNumber(phoneNumber: string): boolean {\n\tif (!phoneNumber || phoneNumber.trim().length === 0) return false;\n\tif (/[a-zA-Z]/.test(phoneNumber)) return false;\n\tconst cleaned = phoneNumber.replace(/\\D/g, \"\");\n\treturn /^\\d{9,12}$/.test(cleaned);\n}\n\n/** Payment ID field configuration for IDR (Indonesia, QRIS). */\nexport const IDR_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"phone\",\n\t\tlabel: \"PHONE_NUMBER\",\n\t\tplaceholder: IDR_PLACEHOLDER,\n\t\tdisplayLabel: \"Phone Number\",\n\t\tvalidate: validateIndonesianPhoneNumber,\n\t\tvalidationErrorMessage: IDR_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Indonesia (IDR). */\nexport const IDR_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Indonesia\",\n\tcurrency: CURRENCY.IDR,\n\tsymbolNative: \"Rp\",\n\tlocale: \"id-ID\",\n\tpaymentMethod: \"QRIS\",\n\tpaymentAddressName: \"PHONE_NUMBER\",\n\ttimezone: \"Asia/Jakarta\",\n\ttimezone_name: \"WIB\",\n\tflag: \"🇮🇩\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1ee-1f1e9.png\",\n\tphoneCode: \"+62\",\n\ttelegramSupportChannel: \"https://t.me/p2pmeindonesia\",\n\ttwitterUsername: \"p2pdotmeID\",\n\tsmsCountryCodes: [],\n\tprecision: 0,\n\tisAlpha: false,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const INR_PLACEHOLDER = \"merchant@upi\";\nexport const INR_VALIDATION_ERROR = \"Please enter a valid UPI ID (e.g., username@bankname)\";\n\n/**\n * Validates UPI ID format.\n * UPI ID format: username@bankname (e.g., john@paytm, user@ybl, 8658404239@kotak811)\n */\nexport function validateUPIId(upiId: string): boolean {\n\tif (!upiId || upiId.trim().length === 0) return false;\n\tconst upiRegex = /^[a-zA-Z0-9.\\-_]{2,256}@[a-zA-Z0-9]{2,64}$/;\n\treturn upiRegex.test(upiId.trim());\n}\n\n/** Payment ID field configuration for INR (India, UPI). */\nexport const INR_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"upi\",\n\t\tlabel: \"UPI_ID\",\n\t\tplaceholder: INR_PLACEHOLDER,\n\t\tdisplayLabel: \"UPI ID\",\n\t\tvalidate: validateUPIId,\n\t\tvalidationErrorMessage: INR_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for India (INR). */\nexport const INR_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"India\",\n\tcurrency: CURRENCY.INR,\n\tsymbolNative: \"₹\",\n\tlocale: \"en-IN\",\n\tpaymentMethod: \"UPI\",\n\tpaymentAddressName: \"UPI_ID\",\n\ttimezone: \"Asia/Kolkata\",\n\ttimezone_name: \"IST\",\n\tflag: \"🇮🇳\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1ee-1f1f3.png\",\n\tphoneCode: \"+91\",\n\ttelegramSupportChannel: \"https://t.me/P2Pdotme\",\n\ttwitterUsername: \"P2Pdotme\",\n\tsmsCountryCodes: [\"IN\"],\n\tprecision: 2,\n\tisAlpha: false,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const MEX_PLACEHOLDER = \"012345678901234567\";\nexport const MEX_VALIDATION_ERROR =\n\t\"Please enter a valid CLABE (18 digits), card number, or phone number\";\n\n/**\n * Validates Mexican payment IDs (CLABE, card number, or phone number).\n * CLABE: 18 digits. Card: 16 digits. Phone: 10 digits.\n */\nexport function validateMexicanPaymentId(paymentId: string): boolean {\n\tif (!paymentId || paymentId.trim().length === 0) return false;\n\n\tconst trimmed = paymentId.trim().replace(/\\D/g, \"\");\n\n\tif (/^\\d{18}$/.test(trimmed)) return true;\n\tif (/^\\d{16}$/.test(trimmed)) return true;\n\tif (/^\\d{10}$/.test(trimmed)) return true;\n\n\treturn false;\n}\n\n/** Payment ID field configuration for MEX (Mexico, SPEI). */\nexport const MEX_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"clabe\",\n\t\tlabel: \"CLABE_ID\",\n\t\tplaceholder: MEX_PLACEHOLDER,\n\t\tdisplayLabel: \"CLABE\",\n\t\tvalidate: validateMexicanPaymentId,\n\t\tvalidationErrorMessage: MEX_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Mexico (MEX). */\nexport const MEX_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Mexico\",\n\tcurrency: CURRENCY.MEX,\n\tinternationalFormat: \"MXN\",\n\tsymbolNative: \"Mx\",\n\tlocale: \"es-MX\",\n\tpaymentMethod: \"SPEI\",\n\tpaymentAddressName: \"CLABE_ID\",\n\ttimezone: \"America/Mexico_City\",\n\ttimezone_name: \"CST\",\n\tflag: \"🇲🇽\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1f2-1f1fd.png\",\n\tphoneCode: \"+52\",\n\ttelegramSupportChannel: \"https://t.me/p2pmemexico\",\n\ttwitterUsername: \"p2pmemexico\",\n\tsmsCountryCodes: [\"MX\"],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [\"PAY\"],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const NGN_PLACEHOLDER = \"0123456789\";\nexport const NGN_PLACEHOLDER_BANK = \"Bank Name\";\nexport const NGN_VALIDATION_ERROR = \"Please enter a valid 10-digit account number\";\n\n/**\n * Validates Nigerian bank account number (NUBAN format, 10 digits).\n */\nexport function validateNigerianAccountNumber(accountNumber: string): boolean {\n\tif (!accountNumber || accountNumber.trim().length === 0) return false;\n\tconst cleaned = accountNumber.trim().replace(/\\D/g, \"\");\n\treturn /^\\d{10}$/.test(cleaned);\n}\n\n/** Payment ID field configuration for NGN (Nigeria, NIP). */\nexport const NGN_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"account\",\n\t\tlabel: \"ACCOUNT_NUMBER\",\n\t\tplaceholder: NGN_PLACEHOLDER,\n\t\tdisplayLabel: \"Account Number\",\n\t\tvalidate: validateNigerianAccountNumber,\n\t\tvalidationErrorMessage: NGN_VALIDATION_ERROR,\n\t},\n\t{\n\t\tkey: \"bank-name\",\n\t\tlabel: \"BANK_NAME\",\n\t\tplaceholder: NGN_PLACEHOLDER_BANK,\n\t\tdisplayLabel: \"Bank Name\",\n\t\tvalidate: (v: string) => v.trim().length > 0,\n\t\tvalidationErrorMessage: NGN_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Nigeria (NGN). */\nexport const NGN_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Nigeria\",\n\tcurrency: CURRENCY.NGN,\n\tsymbolNative: \"₦\",\n\tlocale: \"en-NG\",\n\tpaymentMethod: \"NIP\",\n\tpaymentAddressName: \"ACCOUNT_NUMBER\",\n\ttimezone: \"Africa/Lagos\",\n\ttimezone_name: \"WAT\",\n\tflag: \"🇳🇬\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1f3-1f1ec.png\",\n\tphoneCode: \"+234\",\n\ttelegramSupportChannel: \"https://t.me/p2pmeNigeria\",\n\ttwitterUsername: \"p2pmeNigeria\",\n\tsmsCountryCodes: [\"NG\"],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [\"PAY\"],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\nimport { EUR_PLACEHOLDER, EUR_VALIDATION_ERROR, validateRevolutId } from \"./eur\";\n\nexport const USD_PLACEHOLDER = EUR_PLACEHOLDER;\nexport const USD_VALIDATION_ERROR = EUR_VALIDATION_ERROR;\n\n/** Payment ID field configuration for USD (Revolut USD). */\nexport const USD_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"revolut\",\n\t\tlabel: \"REVOLUT_ID\",\n\t\tplaceholder: USD_PLACEHOLDER,\n\t\tdisplayLabel: \"Revolut ID\",\n\t\tvalidate: validateRevolutId,\n\t\tvalidationErrorMessage: USD_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Revolut USD. */\nexport const USD_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Revolut USD\",\n\tcurrency: CURRENCY.USD,\n\tsymbolNative: \"$\",\n\tlocale: \"en-US\",\n\tpaymentMethod: \"REVOLUT\",\n\tpaymentAddressName: \"REVOLUT_ID\",\n\ttimezone: \"America/New_York\",\n\ttimezone_name: \"EST\",\n\tflag: \"\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f310.png\",\n\tphoneCode: \"+1\",\n\ttelegramSupportChannel: \"https://t.me/P2Pdotme\",\n\ttwitterUsername: \"P2Pdotme\",\n\tsmsCountryCodes: [\"US\"],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [\"PAY\"],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const VEN_PLACEHOLDER = \"04121234567\";\nexport const VEN_PLACEHOLDER_RIF = \"V12345678\";\nexport const VEN_PLACEHOLDER_BANK = \"Banesco\";\n\nexport const VEN_VALIDATION_ERROR = \"Please enter a valid phone number (e.g., 04121234567)\";\nexport const VEN_VALIDATION_ERROR_RIF = \"Please enter a valid RIF (e.g., V12345678)\";\nexport const VEN_VALIDATION_ERROR_BANK = \"Please enter a bank name\";\n\n/**\n * Validates Venezuelan phone number for Pago Movil.\n * Format: 04XX-XXXXXXX (11 digits starting with 04).\n */\nexport function validateVenezuelanPhoneNumber(phoneNumber: string): boolean {\n\tif (!phoneNumber || phoneNumber.trim().length === 0) return false;\n\n\tconst cleaned = phoneNumber.trim().replace(/\\D/g, \"\");\n\n\tif (/^04\\d{9}$/.test(cleaned)) return true;\n\tif (/^4\\d{9}$/.test(cleaned)) return true;\n\n\treturn false;\n}\n\n/**\n * Validates Venezuelan RIF (Registro de Informacion Fiscal).\n * Format: One letter (J/V/E/G/C) followed by 7-9 digits.\n */\nexport function validateVenezuelanRif(rif: string): boolean {\n\tif (!rif || rif.trim().length === 0) return false;\n\tconst trimmed = rif.trim().toUpperCase();\n\treturn /^[JVEGC]\\d{7,9}$/.test(trimmed);\n}\n\n/** Payment ID field configuration for VEN (Venezuela, Pago Móvil). */\nexport const VEN_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"phone\",\n\t\tlabel: \"PHONE_NUMBER\",\n\t\tplaceholder: VEN_PLACEHOLDER,\n\t\tdisplayLabel: \"Phone\",\n\t\tvalidate: validateVenezuelanPhoneNumber,\n\t\tvalidationErrorMessage: VEN_VALIDATION_ERROR,\n\t},\n\t{\n\t\tkey: \"rif\",\n\t\tlabel: \"RIF_LABEL\",\n\t\tplaceholder: VEN_PLACEHOLDER_RIF,\n\t\tdisplayLabel: \"RIF\",\n\t\tvalidate: validateVenezuelanRif,\n\t\tvalidationErrorMessage: VEN_VALIDATION_ERROR_RIF,\n\t},\n\t{\n\t\tkey: \"bank\",\n\t\tlabel: \"BANK_LABEL\",\n\t\tplaceholder: VEN_PLACEHOLDER_BANK,\n\t\tdisplayLabel: \"Banco\",\n\t\tvalidate: (v: string) => v.trim().length > 0,\n\t\tvalidationErrorMessage: VEN_VALIDATION_ERROR_BANK,\n\t},\n];\n\n/** Country option for Venezuela (VEN). */\nexport const VEN_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Venezuela\",\n\tcurrency: CURRENCY.VEN,\n\tinternationalFormat: \"VES\",\n\tsymbolNative: \"Bs\",\n\tlocale: \"es-VE\",\n\tpaymentMethod: \"PAGO_MOVIL\",\n\tpaymentAddressName: \"PAGO_MOVIL_DETAILS\",\n\ttimezone: \"America/Caracas\",\n\ttimezone_name: \"VET\",\n\tflag: \"🇻🇪\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1fb-1f1ea.png\",\n\tphoneCode: \"+58\",\n\ttelegramSupportChannel: \"https://t.me/p2pmevenezuela\",\n\ttwitterUsername: \"p2pmevenezuela\",\n\tsmsCountryCodes: [\"VE\"],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import {\n\tARS_COUNTRY_OPTION,\n\tBRL_COUNTRY_OPTION,\n\tCOP_COUNTRY_OPTION,\n\tEUR_COUNTRY_OPTION,\n\tIDR_COUNTRY_OPTION,\n\tINR_COUNTRY_OPTION,\n\tMEX_COUNTRY_OPTION,\n\tNGN_COUNTRY_OPTION,\n\tUSD_COUNTRY_OPTION,\n\tVEN_COUNTRY_OPTION,\n} from \"./currencies\";\nimport type { CountryOption } from \"./types\";\n\n/** All supported countries with their currency metadata, payment methods, and display config. */\nexport const COUNTRY_OPTIONS: readonly CountryOption[] = [\n\tINR_COUNTRY_OPTION,\n\tIDR_COUNTRY_OPTION,\n\tBRL_COUNTRY_OPTION,\n\tARS_COUNTRY_OPTION,\n\tMEX_COUNTRY_OPTION,\n\tVEN_COUNTRY_OPTION,\n\tNGN_COUNTRY_OPTION,\n\tCOP_COUNTRY_OPTION,\n\tEUR_COUNTRY_OPTION,\n\tUSD_COUNTRY_OPTION,\n];\n","import { err, ok, type Result } from \"neverthrow\";\nimport { COUNTRY_OPTIONS } from \"../country\";\nimport type { CurrencyCode } from \"../types\";\nimport { QRParserError, type QRParserErrorCode } from \"./errors\";\n\n/** Currencies that support QR parsing — derived from countries where PAY is not disabled. */\nexport const SUPPORTED_QR_CURRENCIES: readonly CurrencyCode[] = COUNTRY_OPTIONS.filter(\n\t(c) => !c.disabledPaymentTypes.includes(\"PAY\"),\n).map((c) => c.currency);\n\nexport type SupportedCurrency = (typeof SUPPORTED_QR_CURRENCIES)[number];\n\n/** Internal — options forwarded to per-currency parsers (today, only PIX uses them). */\nexport interface ParseQRConfig {\n\tproxyUrl?: string;\n\torderId?: string;\n}\n\n/** Single-object params for `parseQR`. */\nexport interface ParseQRParams {\n\treadonly qrData: string;\n\treadonly currency: SupportedCurrency;\n\t/** Exchange rate: 1 USDC = `sellPrice` fiat. */\n\treadonly sellPrice: number;\n\t/** Required for dynamic PIX (BRL) QRs to bypass CORS on the bank endpoint. */\n\treadonly proxyUrl?: string;\n\t/** Forwarded to `proxyUrl` for tracing / correlation. */\n\treadonly orderId?: string;\n}\n\nexport interface ParsedQR {\n\tpaymentAddress: string;\n\tamount?: {\n\t\tusdc: number;\n\t\tfiat: number;\n\t};\n}\n\nexport type ParseResult = Result<ParsedQR, QRParserError>;\n\nexport function success(data: ParsedQR): ParseResult {\n\treturn ok(data);\n}\n\nexport function failure(\n\tcode: QRParserErrorCode,\n\tmessage: string,\n\tcontext?: Record<string, unknown>,\n): ParseResult {\n\treturn err(new QRParserError(message, { code, context }));\n}\n","/**\n * Calculate CRC-16-CCITT-FALSE checksum.\n * Polynomial 0x1021, initial value 0xFFFF.\n * Used by EMVCo-compliant QR codes (PIX, MercadoPago).\n */\nexport function calculateCRC16(data: string): string {\n\tconst payload = `${data}6304`;\n\tconst polynomial = 0x1021;\n\tlet result = 0xffff;\n\n\tconst encoder = new TextEncoder();\n\tconst bytes = encoder.encode(payload);\n\n\tfor (let offset = 0; offset < bytes.length; offset++) {\n\t\tresult ^= bytes[offset] << 8;\n\t\tfor (let bitwise = 0; bitwise < 8; bitwise++) {\n\t\t\tresult <<= 1;\n\t\t\tif (result & 0x10000) {\n\t\t\t\tresult ^= polynomial;\n\t\t\t}\n\t\t\tresult &= 0xffff;\n\t\t}\n\t}\n\n\treturn result.toString(16).toUpperCase().padStart(4, \"0\");\n}\n\n/**\n * Verify CRC-16 checksum of an EMVCo QR string.\n * Expects the string to end with \"6304\" + 4 hex CRC digits.\n */\nexport function verifyCRC16(qrData: string): { valid: boolean; error?: string } {\n\tif (!qrData || qrData.length < 8) {\n\t\treturn { valid: false, error: \"QR data too short for CRC verification\" };\n\t}\n\n\tconst crcTagIndex = qrData.lastIndexOf(\"6304\");\n\tif (crcTagIndex === -1 || crcTagIndex + 8 !== qrData.length) {\n\t\treturn { valid: false, error: \"Missing or misplaced CRC tag (6304)\" };\n\t}\n\n\tconst providedCrc = qrData.substring(crcTagIndex + 4, crcTagIndex + 8);\n\tif (!/^[0-9A-Fa-f]{4}$/.test(providedCrc)) {\n\t\treturn { valid: false, error: \"Invalid CRC hex format\" };\n\t}\n\n\tconst dataBeforeCrc = qrData.substring(0, crcTagIndex);\n\tconst calculatedCrc = calculateCRC16(dataBeforeCrc);\n\n\tif (calculatedCrc !== providedCrc.toUpperCase()) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `CRC mismatch: expected ${calculatedCrc}, got ${providedCrc.toUpperCase()}`,\n\t\t};\n\t}\n\n\treturn { valid: true };\n}\n","/**\n * Parse a TLV (Tag-Length-Value) encoded string.\n * Tags are 2 digits, lengths are 2 digits (EMVCo standard).\n * Returns all parsed tag-value pairs. Stops gracefully on truncated data.\n */\nexport function parseTLV(data: string): { tag: string; value: string }[] {\n\tconst entries: { tag: string; value: string }[] = [];\n\tlet pos = 0;\n\n\twhile (pos + 4 <= data.length) {\n\t\tconst tag = data.substring(pos, pos + 2);\n\t\tconst lengthStr = data.substring(pos + 2, pos + 4);\n\n\t\tif (!/^[0-9]{2}$/.test(tag) || !/^[0-9]{2}$/.test(lengthStr)) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst length = parseInt(lengthStr, 10);\n\t\tif (pos + 4 + length > data.length) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst value = data.substring(pos + 4, pos + 4 + length);\n\t\tentries.push({ tag, value });\n\t\tpos += 4 + length;\n\t}\n\n\treturn entries;\n}\n\n/**\n * Extract specific tags from a TLV string.\n * Returns a record mapping tag IDs to their values.\n * Only includes tags present in the `tags` array.\n */\nexport function extractTags(data: string, tags: string[]): Record<string, string> {\n\tconst result: Record<string, string> = {};\n\tconst tagSet = new Set(tags);\n\n\tfor (const entry of parseTLV(data)) {\n\t\tif (tagSet.has(entry.tag)) {\n\t\t\tresult[entry.tag] = entry.value;\n\t\t}\n\t}\n\n\treturn result;\n}\n","import type { ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\nimport { verifyCRC16 } from \"../utils/crc16\";\nimport { extractTags } from \"../utils/tlv\";\n\nexport function parseMercadoPago(qrData: string, _sellPrice: number): ParseResult {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\n\tconst isARS = trimmed.includes(\"5303032\");\n\tconst isAR = trimmed.includes(\"5802AR\");\n\tif (!isARS && !isAR) {\n\t\treturn failure(\"INVALID_QR\", \"Not an ARS/Argentina QR code\");\n\t}\n\n\tconst crc = verifyCRC16(trimmed);\n\tif (!crc.valid) {\n\t\treturn failure(\"INVALID_QR\", \"Invalid QR checksum\");\n\t}\n\n\tconst tags = extractTags(trimmed, [\"59\"]);\n\tconst merchantName = tags[\"59\"] || \"Unknown\";\n\n\treturn success({ paymentAddress: merchantName });\n}\n","import { err, ok, type Result } from \"neverthrow\";\nimport { QRParserError, type QRParserErrorCode } from \"../errors\";\nimport type { ParsedQR, ParseQRConfig, ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\nimport { parseAmount } from \"../utils/amount\";\nimport { verifyCRC16 } from \"../utils/crc16\";\nimport { parseTLV } from \"../utils/tlv\";\n\nconst PIX_TAGS = {\n\tPAYLOAD_FORMAT: \"00\",\n\tPIX_KEY_INFO: \"26\",\n\tAMOUNT: \"54\",\n\tMERCHANT_NAME: \"59\",\n\tCRC: \"63\",\n} as const;\n\nfunction parsePIXKeyInfo(data: string): { pixKey: string | null; location: string | null } {\n\tconst result = { pixKey: null as string | null, location: null as string | null };\n\n\tfor (const entry of parseTLV(data)) {\n\t\tif (entry.tag === \"01\") {\n\t\t\tif (entry.value.includes(\"http\") || entry.value.includes(\"://\")) {\n\t\t\t\tresult.location = entry.value.startsWith(\"http\") ? entry.value : `https://${entry.value}`;\n\t\t\t} else {\n\t\t\t\tresult.pixKey = entry.value;\n\t\t\t}\n\t\t} else if (entry.tag === \"25\") {\n\t\t\tresult.location = entry.value.startsWith(\"http\") ? entry.value : `https://${entry.value}`;\n\t\t}\n\t}\n\n\treturn result;\n}\n\nfunction safeBase64Decode(base64String: string): string {\n\tif (typeof globalThis.atob === \"function\") {\n\t\treturn globalThis.atob(base64String);\n\t}\n\tthrow new Error(\"No base64 decoder available\");\n}\n\ninterface PIXJWTPayload {\n\tstatus?: string;\n\ttxid?: string;\n\tvalor?: { original?: string };\n\tcalendario?: { expiracao?: number };\n}\n\nfunction parseJWT(token: string): PIXJWTPayload | null {\n\ttry {\n\t\tconst parts = token.trim().split(\".\");\n\t\tif (parts.length !== 3 || !parts[0] || !parts[1] || !parts[2]) return null;\n\t\tconst json = safeBase64Decode(parts[1]);\n\t\treturn JSON.parse(json) as PIXJWTPayload;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction dynamicErr(\n\tcode: QRParserErrorCode,\n\tmessage: string,\n): Result<{ dynamicAmount?: string }, QRParserError> {\n\treturn err(new QRParserError(message, { code }));\n}\n\nasync function fetchDynamicData(\n\tlocation: string,\n\tproxyUrl: string,\n\torderId?: string,\n): Promise<Result<{ dynamicAmount?: string }, QRParserError>> {\n\ttry {\n\t\tconst url = new URL(`${proxyUrl}/pix`);\n\t\turl.searchParams.set(\"locationUrl\", location);\n\t\tif (orderId) {\n\t\t\turl.searchParams.set(\"orderId\", orderId);\n\t\t}\n\n\t\tconst response = await fetch(url, {\n\t\t\tmethod: \"GET\",\n\t\t\theaders: { Accept: \"*/*\" },\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\treturn dynamicErr(\"FETCH_FAILED\", `Proxy error: ${response.status} ${response.statusText}`);\n\t\t}\n\n\t\tconst jwtToken = await response.text();\n\t\tconst payload = parseJWT(jwtToken);\n\n\t\tif (!payload) {\n\t\t\treturn dynamicErr(\"FETCH_FAILED\", \"Failed to parse dynamic PIX response\");\n\t\t}\n\n\t\treturn ok({ dynamicAmount: payload.valor?.original });\n\t} catch (error) {\n\t\tconst msg = error instanceof Error ? error.message : \"Unknown error\";\n\t\treturn dynamicErr(\"FETCH_FAILED\", `Failed to fetch dynamic PIX data: ${msg}`);\n\t}\n}\n\nexport async function parsePIX(\n\tqrData: string,\n\tsellPrice: number,\n\tconfig: ParseQRConfig,\n): Promise<ParseResult> {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\n\tconst crc = verifyCRC16(trimmed);\n\tif (!crc.valid) {\n\t\treturn failure(\"INVALID_QR\", \"Invalid QR checksum\");\n\t}\n\n\tconst allTags: Record<string, string> = {};\n\tfor (const entry of parseTLV(trimmed)) {\n\t\tallTags[entry.tag] = entry.value;\n\t}\n\n\tif (!allTags[PIX_TAGS.PAYLOAD_FORMAT]) {\n\t\treturn failure(\"INVALID_QR\", \"Invalid PIX QR format\");\n\t}\n\n\tconst merchantName = allTags[PIX_TAGS.MERCHANT_NAME] || \"MERCHANT_NOT_FOUND\";\n\n\tlet dynamicAmount: string | undefined;\n\tconst pixKeyData = allTags[PIX_TAGS.PIX_KEY_INFO];\n\tif (pixKeyData) {\n\t\tconst { location } = parsePIXKeyInfo(pixKeyData);\n\t\tif (location) {\n\t\t\tif (!config.proxyUrl) {\n\t\t\t\treturn failure(\"FETCH_FAILED\", \"proxyUrl is required for dynamic PIX QR codes\");\n\t\t\t}\n\t\t\tconst dynamicResult = await fetchDynamicData(location, config.proxyUrl, config.orderId);\n\t\t\tif (dynamicResult.isErr()) {\n\t\t\t\treturn err(dynamicResult.error);\n\t\t\t}\n\t\t\tdynamicAmount = dynamicResult.value.dynamicAmount;\n\t\t}\n\t}\n\n\tconst fiatAmountStr = dynamicAmount || allTags[PIX_TAGS.AMOUNT];\n\tconst result: ParsedQR = { paymentAddress: merchantName };\n\n\tif (fiatAmountStr) {\n\t\tconst amount = parseAmount(fiatAmountStr, sellPrice);\n\t\tif (amount) {\n\t\t\tresult.amount = amount;\n\t\t}\n\t}\n\n\treturn success(result);\n}\n","/**\n * Parse a fiat amount string and convert to usdc using sellPrice.\n * Returns null if the amount is not parseable or <= 0.\n */\nexport function parseAmount(\n\tamountStr: string,\n\tsellPrice: number,\n): { usdc: number; fiat: number } | null {\n\tif (!amountStr || amountStr.trim() === \"\") return null;\n\n\tconst fiat = parseFloat(amountStr.trim());\n\tif (Number.isNaN(fiat) || fiat <= 0) return null;\n\n\treturn { usdc: fiat / sellPrice, fiat };\n}\n","import type { ParsedQR, ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\nimport { parseAmount } from \"../utils/amount\";\nimport { extractTags } from \"../utils/tlv\";\n\nconst QRIS_TAGS = { AMOUNT: \"54\", MERCHANT_NAME: \"59\" } as const;\n\nexport function parseQRIS(qrData: string, sellPrice: number): ParseResult {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\tconst tags = extractTags(trimmed, [QRIS_TAGS.AMOUNT, QRIS_TAGS.MERCHANT_NAME]);\n\n\tconst merchantName = tags[QRIS_TAGS.MERCHANT_NAME];\n\tif (!merchantName) {\n\t\treturn failure(\"INVALID_QR\", \"Missing merchant name\");\n\t}\n\n\tconst result: ParsedQR = { paymentAddress: merchantName };\n\n\tconst amountStr = tags[QRIS_TAGS.AMOUNT];\n\tif (amountStr) {\n\t\tconst amount = parseAmount(amountStr, sellPrice);\n\t\tif (!amount) {\n\t\t\treturn failure(\"INVALID_AMOUNT\", \"Invalid amount in QR\");\n\t\t}\n\t\tresult.amount = amount;\n\t}\n\n\treturn success(result);\n}\n","import type { ParsedQR, ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\nimport { parseAmount } from \"../utils/amount\";\n\nconst UPI_ID_REGEX = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+$/;\n\nexport function parseUPI(qrData: string, sellPrice: number): ParseResult {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\n\tlet paramString: string;\n\tif (trimmed.startsWith(\"upi://pay?\")) {\n\t\tparamString = trimmed.substring(10);\n\t} else if (trimmed.includes(\"?\")) {\n\t\tparamString = trimmed.split(\"?\")[1];\n\t} else {\n\t\tparamString = trimmed;\n\t}\n\n\tconst params = new URLSearchParams(paramString);\n\tconst pa = params.get(\"pa\");\n\n\tif (!pa) {\n\t\treturn failure(\"INVALID_QR\", \"Missing UPI payment address\");\n\t}\n\n\tif (!UPI_ID_REGEX.test(pa)) {\n\t\treturn failure(\"INVALID_QR\", \"Invalid UPI ID format\");\n\t}\n\n\tconst result: ParsedQR = { paymentAddress: pa };\n\n\tconst amountStr = params.get(\"am\");\n\tif (amountStr) {\n\t\tconst amount = parseAmount(amountStr, sellPrice);\n\t\tif (!amount) {\n\t\t\treturn failure(\"INVALID_AMOUNT\", \"Invalid amount in QR\");\n\t\t}\n\t\tresult.amount = amount;\n\t}\n\n\treturn success(result);\n}\n","import type { ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\n\nexport function parsePagoMovil(qrData: string, _sellPrice: number): ParseResult {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\n\tconst qIdx = trimmed.indexOf(\"?\");\n\tif (qIdx === -1) {\n\t\treturn failure(\"INVALID_QR\", \"Not a valid Venezuelan QR code\");\n\t}\n\n\tconst payload = trimmed.substring(0, qIdx);\n\n\tif (!payload || !/^[A-Za-z0-9+/=]+$/.test(payload)) {\n\t\treturn failure(\"INVALID_QR\", \"Not a valid Venezuelan QR code\");\n\t}\n\n\treturn success({ paymentAddress: trimmed });\n}\n","import { CURRENCY } from \"../country\";\nimport { parseMercadoPago } from \"./parsers/ars\";\nimport { parsePIX } from \"./parsers/brl\";\nimport { parseQRIS } from \"./parsers/idr\";\nimport { parseUPI } from \"./parsers/inr\";\nimport { parsePagoMovil } from \"./parsers/ven\";\nimport type { ParseQRParams, ParseResult } from \"./types\";\nimport { failure } from \"./types\";\n\n/**\n * Parses a QR string for the given currency and returns the extracted payment data.\n *\n * This dispatcher is `async` because dynamic PIX (BRL) QRs store the amount\n * behind a location URL pointing at the issuing bank's PIX endpoint. The SDK\n * resolves that URL via a CORS-bypassing proxy (see `proxyUrl`), which returns\n * a signed JWT whose `valor.original` field holds the amount. All other parsers\n * (UPI, QRIS, MercadoPago, PagoMovil) and static PIX are synchronous and resolve\n * immediately.\n */\nexport async function parseQR(params: ParseQRParams): Promise<ParseResult> {\n\tconst { qrData, currency, sellPrice, proxyUrl, orderId } = params;\n\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tswitch (currency) {\n\t\tcase CURRENCY.INR:\n\t\t\treturn parseUPI(qrData, sellPrice);\n\t\tcase CURRENCY.IDR:\n\t\t\treturn parseQRIS(qrData, sellPrice);\n\t\tcase CURRENCY.BRL:\n\t\t\treturn parsePIX(qrData, sellPrice, { proxyUrl, orderId });\n\t\tcase CURRENCY.ARS:\n\t\t\treturn parseMercadoPago(qrData, sellPrice);\n\t\tcase CURRENCY.VEN:\n\t\t\treturn parsePagoMovil(qrData, sellPrice);\n\t\tdefault:\n\t\t\treturn failure(\"INVALID_CURRENCY\", `Currency \"${currency}\" is not supported`);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACC,SACA,SAKC;AACD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO,QAAQ;AACpB,SAAK,QAAQ,QAAQ;AACrB,SAAK,UAAU,QAAQ;AAAA,EACxB;AACD;;;AClBO,IAAM,WAAW;AAAA,EACvB,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACN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HA,eAAsB,QAAQ,QAA6C;AAC1E,QAAM,EAAE,QAAQ,UAAU,WAAW,UAAU,QAAQ,IAAI;AAE3D,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,OAAO,KAAK,EAAE,WAAW,GAAG;AACxE,WAAO,QAAQ,cAAc,6BAA6B;AAAA,EAC3D;AAEA,UAAQ,UAAU;AAAA,IACjB,KAAK,SAAS;AACb,aAAO,SAAS,QAAQ,SAAS;AAAA,IAClC,KAAK,SAAS;AACb,aAAO,UAAU,QAAQ,SAAS;AAAA,IACnC,KAAK,SAAS;AACb,aAAO,SAAS,QAAQ,WAAW,EAAE,UAAU,QAAQ,CAAC;AAAA,IACzD,KAAK,SAAS;AACb,aAAO,iBAAiB,QAAQ,SAAS;AAAA,IAC1C,KAAK,SAAS;AACb,aAAO,eAAe,QAAQ,SAAS;AAAA,IACxC;AACC,aAAO,QAAQ,oBAAoB,aAAa,QAAQ,oBAAoB;AAAA,EAC9E;AACD;","names":["import_neverthrow"]}
1
+ {"version":3,"sources":["../src/qr-parsers/index.ts","../src/qr-parsers/errors.ts","../src/country/currency.ts","../src/country/currencies/ars.ts","../src/country/currencies/brl.ts","../src/country/currencies/cop.ts","../src/country/currencies/eur.ts","../src/country/currencies/idr.ts","../src/country/currencies/inr.ts","../src/country/currencies/mex.ts","../src/country/currencies/ngn.ts","../src/country/currencies/usd.ts","../src/country/currencies/ven.ts","../src/country/countries.ts","../src/qr-parsers/types.ts","../src/qr-parsers/utils/crc16.ts","../src/qr-parsers/utils/tlv.ts","../src/qr-parsers/parsers/ars.ts","../src/qr-parsers/parsers/brl.ts","../src/qr-parsers/utils/amount.ts","../src/qr-parsers/parsers/idr.ts","../src/qr-parsers/parsers/inr.ts","../src/qr-parsers/parsers/ngn.ts","../src/qr-parsers/parsers/ven.ts","../src/qr-parsers/parse-qr.ts"],"sourcesContent":["export { QRParserError, type QRParserErrorCode } from \"./errors\";\nexport { parseQR } from \"./parse-qr\";\nexport type {\n\tParsedQR,\n\tParseQRParams,\n\tParseResult,\n\tSupportedCurrency,\n} from \"./types\";\n","export type QRParserErrorCode =\n\t| \"INVALID_QR\"\n\t| \"INVALID_CURRENCY\"\n\t| \"INVALID_AMOUNT\"\n\t| \"FETCH_FAILED\";\n\nexport class QRParserError extends Error {\n\treadonly code: QRParserErrorCode;\n\treadonly cause?: unknown;\n\treadonly context?: Record<string, unknown>;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\tcode: QRParserErrorCode;\n\t\t\tcause?: unknown;\n\t\t\tcontext?: Record<string, unknown>;\n\t\t},\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"QRParserError\";\n\t\tthis.code = options.code;\n\t\tthis.cause = options.cause;\n\t\tthis.context = options.context;\n\t}\n}\n","/**\n * All supported currency symbols. Single source of truth for the SDK.\n *\n * Lives alongside the country metadata so that adding a currency is a\n * single-folder operation: drop a new file in `currencies/<code>.ts`, add it\n * to this map, and both `COUNTRY_OPTIONS` and `ZodCurrencySchema` pick it up.\n */\nexport const CURRENCY = {\n\tIDR: \"IDR\",\n\tINR: \"INR\",\n\tBRL: \"BRL\",\n\tARS: \"ARS\",\n\tMEX: \"MEX\",\n\tVEN: \"VEN\",\n\tEUR: \"EUR\",\n\tNGN: \"NGN\",\n\tUSD: \"USD\",\n\tCOP: \"COP\",\n} as const;\n\n/** Union of supported currency codes. */\nexport type CurrencyCode = (typeof CURRENCY)[keyof typeof CURRENCY];\n\n/**\n * Tuple form of the currency codes — used by `z.enum(...)` in the shared\n * validation layer. Narrow tuple type required by Zod.\n */\nexport const CURRENCY_CODES = Object.values(CURRENCY) as [CurrencyCode, ...CurrencyCode[]];\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const ARS_PLACEHOLDER = \"juan.perez\";\nexport const ARS_VALIDATION_ERROR =\n\t\"Please enter a valid CBU/CVU (22 digits) or Alias (6-20 characters)\";\n\n/** Validates CBU (Clave Bancaria Uniforme) — Argentine banking key, 22 digits with checksums. */\nfunction validateCBU(cbu: string): boolean {\n\tif (cbu.length !== 22) return false;\n\tif (/^(\\d)\\1{21}$/.test(cbu)) return false;\n\n\tconst bankCode = cbu.substring(0, 7);\n\tconst bankCheckDigit = parseInt(cbu[7], 10);\n\tlet sum = 0;\n\tconst weights = [7, 1, 3, 9, 7, 1, 3];\n\tfor (let i = 0; i < 7; i++) {\n\t\tsum += parseInt(bankCode[i], 10) * weights[i];\n\t}\n\tconst calculatedBankCheck = (10 - (sum % 10)) % 10;\n\tif (bankCheckDigit !== calculatedBankCheck) return false;\n\n\tconst accountNumber = cbu.substring(8, 21);\n\tconst accountCheckDigit = parseInt(cbu[21], 10);\n\tsum = 0;\n\tconst accountWeights = [3, 9, 7, 1, 3, 9, 7, 1, 3, 9, 7, 1, 3];\n\tfor (let i = 0; i < 13; i++) {\n\t\tsum += parseInt(accountNumber[i], 10) * accountWeights[i];\n\t}\n\tconst calculatedAccountCheck = (10 - (sum % 10)) % 10;\n\tif (accountCheckDigit !== calculatedAccountCheck) return false;\n\n\treturn true;\n}\n\n/**\n * Validates Argentine payment IDs (CBU, CVU, or Alias).\n * CBU/CVU: 22 digits with checksum. Alias: 6-20 alphanumeric characters.\n */\nexport function validateArgentinePaymentId(paymentId: string): boolean {\n\tif (!paymentId || paymentId.trim().length === 0) return false;\n\n\tconst trimmedPaymentId = paymentId.trim();\n\n\tif (/^\\d{22}$/.test(trimmedPaymentId)) return validateCBU(trimmedPaymentId);\n\tif (/^[a-zA-Z0-9.\\-_]{6,20}$/.test(trimmedPaymentId)) return true;\n\n\treturn false;\n}\n\n/** Payment ID field configuration for ARS (Argentina, ALIAS). */\nexport const ARS_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"alias\",\n\t\tlabel: \"ALIAS_ID\",\n\t\tplaceholder: ARS_PLACEHOLDER,\n\t\tdisplayLabel: \"Alias\",\n\t\tvalidate: validateArgentinePaymentId,\n\t\tvalidationErrorMessage: ARS_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Argentina (ARS). */\nexport const ARS_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Argentina\",\n\tcurrency: CURRENCY.ARS,\n\tsymbolNative: \"$\",\n\tlocale: \"es-AR\",\n\tpaymentMethod: \"ALIAS\",\n\tpaymentAddressName: \"ALIAS_ID\",\n\ttimezone: \"America/Argentina/Buenos_Aires\",\n\ttimezone_name: \"ART\",\n\tflag: \"🇦🇷\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1e6-1f1f7.png\",\n\tphoneCode: \"+54\",\n\ttelegramSupportChannel: \"https://t.me/p2pmeargentina\",\n\ttwitterUsername: \"p2pmeargentina\",\n\tsmsCountryCodes: [\"AR\"],\n\tprecision: 2,\n\tisAlpha: false,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const BRL_PLACEHOLDER = \"Chave pix ou pix copia e cola\";\nexport const BRL_VALIDATION_ERROR = \"Please enter a valid PIX ID\";\n\n/** Validates CPF (Brazilian tax ID for individuals). */\nfunction validateCPF(cpf: string): boolean {\n\tif (cpf.length !== 11) return false;\n\tif (/^(\\d)\\1{10}$/.test(cpf)) return false;\n\n\tlet sum = 0;\n\tfor (let i = 0; i < 9; i++) {\n\t\tsum += parseInt(cpf[i], 10) * (10 - i);\n\t}\n\tlet remainder = sum % 11;\n\tconst firstDigit = remainder < 2 ? 0 : 11 - remainder;\n\tif (parseInt(cpf[9], 10) !== firstDigit) return false;\n\n\tsum = 0;\n\tfor (let i = 0; i < 10; i++) {\n\t\tsum += parseInt(cpf[i], 10) * (11 - i);\n\t}\n\tremainder = sum % 11;\n\tconst secondDigit = remainder < 2 ? 0 : 11 - remainder;\n\treturn parseInt(cpf[10], 10) === secondDigit;\n}\n\n/** Validates CNPJ (Brazilian tax ID for companies). */\nfunction validateCNPJ(cnpj: string): boolean {\n\tif (cnpj.length !== 14) return false;\n\tif (/^(\\d)\\1{13}$/.test(cnpj)) return false;\n\n\tlet sum = 0;\n\tconst weights1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];\n\tfor (let i = 0; i < 12; i++) {\n\t\tsum += parseInt(cnpj[i], 10) * weights1[i];\n\t}\n\tlet remainder = sum % 11;\n\tconst firstDigit = remainder < 2 ? 0 : 11 - remainder;\n\tif (parseInt(cnpj[12], 10) !== firstDigit) return false;\n\n\tsum = 0;\n\tconst weights2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];\n\tfor (let i = 0; i < 13; i++) {\n\t\tsum += parseInt(cnpj[i], 10) * weights2[i];\n\t}\n\tremainder = sum % 11;\n\tconst secondDigit = remainder < 2 ? 0 : 11 - remainder;\n\treturn parseInt(cnpj[13], 10) === secondDigit;\n}\n\n/**\n * Validates PIX ID format.\n * PIX can be: CPF (11 digits), CNPJ (14 digits), email, phone (10–11 digits or E.164),\n * random key (UUID), or a PIX \"copia e cola\" EMV QR payload (starts with 000201).\n */\nexport function validatePIXId(pixId: string): boolean {\n\tif (!pixId || pixId.trim().length === 0) return false;\n\n\tconst trimmedPixId = pixId.trim();\n\n\t// PIX \"copia e cola\" — EMV QR code payload\n\tif (/^000201/.test(trimmedPixId)) return true;\n\n\t// 11 digits: valid CPF or Brazilian mobile phone key (DDD 11–99 + digit 9 + 8 digits)\n\tif (/^\\d{11}$/.test(trimmedPixId))\n\t\treturn validateCPF(trimmedPixId) || /^[1-9][1-9]9\\d{8}$/.test(trimmedPixId);\n\tif (/^\\d{14}$/.test(trimmedPixId)) return validateCNPJ(trimmedPixId);\n\tif (/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(trimmedPixId)) return true;\n\t// Phone key: 10–11 digits (with or without country code prefix)\n\tif (/^\\d{10,11}$/.test(trimmedPixId)) return true;\n\tif (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(trimmedPixId))\n\t\treturn true;\n\n\treturn false;\n}\n\n/** Payment ID field configuration for BRL (Brazil, PIX). */\nexport const BRL_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"pix\",\n\t\tlabel: \"PIX_ID\",\n\t\tplaceholder: BRL_PLACEHOLDER,\n\t\tdisplayLabel: \"PIX ID\",\n\t\tvalidate: validatePIXId,\n\t\tvalidationErrorMessage: BRL_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Brazil (BRL). */\nexport const BRL_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Brazil\",\n\tcurrency: CURRENCY.BRL,\n\tsymbolNative: \"R$\",\n\tlocale: \"pt-BR\",\n\tpaymentMethod: \"PIX\",\n\tpaymentAddressName: \"PIX_ID\",\n\ttimezone: \"America/Sao_Paulo\",\n\ttimezone_name: \"BRT\",\n\tflag: \"🇧🇷\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1e7-1f1f7.png\",\n\tphoneCode: \"+55\",\n\ttelegramSupportChannel: \"https://t.me/p2pmebrasil\",\n\ttwitterUsername: \"p2pmebrasil\",\n\tsmsCountryCodes: [\"BR\"],\n\tprecision: 2,\n\tisAlpha: false,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const COP_PLACEHOLDER = \"juan.perez@nequi.com.co\";\nexport const COP_VALIDATION_ERROR =\n\t\"Please enter a valid Nequi or Daviplata ID (e.g., 3001234567 or email)\";\n\n/**\n * Validates Colombian payment ID for Nequi or Daviplata.\n * Accepts a 10-digit phone number starting with 3, or a valid email address.\n */\nexport function validateColombianPaymentId(paymentId: string): boolean {\n\tif (!paymentId || paymentId.trim().length === 0) return false;\n\tconst trimmed = paymentId.trim();\n\tif (/^3\\d{9}$/.test(trimmed)) return true;\n\tif (/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(trimmed)) return true;\n\treturn false;\n}\n\n/** Payment ID field configuration for COP (Colombia, Transferencia). */\nexport const COP_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"alias\",\n\t\tlabel: \"ALIAS_TRANSFERENCIA\",\n\t\tplaceholder: COP_PLACEHOLDER,\n\t\tdisplayLabel: \"Nequi / Daviplata\",\n\t\tvalidate: validateColombianPaymentId,\n\t\tvalidationErrorMessage: COP_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Colombia (COP). */\nexport const COP_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Colombia\",\n\tcurrency: CURRENCY.COP,\n\tsymbolNative: \"$\",\n\tlocale: \"es-CO\",\n\tpaymentMethod: \"TRANSFERENCIA\",\n\tpaymentAddressName: \"ALIAS_TRANSFERENCIA\",\n\ttimezone: \"America/Bogota\",\n\ttimezone_name: \"COT\",\n\tflag: \"🇨🇴\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1e8-1f1f4.png\",\n\tphoneCode: \"+57\",\n\ttelegramSupportChannel: \"https://t.me/p2pmeColombia\",\n\ttwitterUsername: \"p2pmeColombia\",\n\tsmsCountryCodes: [\"CO\"],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [\"PAY\"],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const EUR_PLACEHOLDER = \"@username or email\";\nexport const EUR_VALIDATION_ERROR = \"Please enter a valid Revolut ID (username, email, or phone)\";\n\n/**\n * Validates Revolut ID (username, email, or phone number).\n */\nexport function validateRevolutId(revolutId: string): boolean {\n\tif (!revolutId || revolutId.trim().length === 0) return false;\n\n\tconst trimmed = revolutId.trim();\n\n\tif (/^@?[a-zA-Z0-9._-]{3,30}$/.test(trimmed)) return true;\n\tif (/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(trimmed)) return true;\n\tif (/^\\+?\\d{7,15}$/.test(trimmed)) return true;\n\n\treturn false;\n}\n\n/** Payment ID field configuration for EUR (Revolut EUR). */\nexport const EUR_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"revolut\",\n\t\tlabel: \"REVOLUT_ID\",\n\t\tplaceholder: EUR_PLACEHOLDER,\n\t\tdisplayLabel: \"Revolut ID\",\n\t\tvalidate: validateRevolutId,\n\t\tvalidationErrorMessage: EUR_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Revolut EUR. */\nexport const EUR_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Revolut EUR\",\n\tcurrency: CURRENCY.EUR,\n\tsymbolNative: \"€\",\n\tlocale: \"de-DE\",\n\tpaymentMethod: \"REVOLUT\",\n\tpaymentAddressName: \"REVOLUT_ID\",\n\ttimezone: \"Europe/Berlin\",\n\ttimezone_name: \"CET\",\n\tflag: \"\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f310.png\",\n\tphoneCode: \"\",\n\ttelegramSupportChannel: \"https://t.me/P2Pdotme\",\n\ttwitterUsername: \"P2Pdotme\",\n\tsmsCountryCodes: [],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [\"PAY\"],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const IDR_PLACEHOLDER = \"8123456789\";\nexport const IDR_VALIDATION_ERROR =\n\t\"Please enter a valid Indonesian phone number (e.g., 8123456789)\";\n\n/**\n * Validates Indonesian phone number.\n * Validates just the number part (9-12 digits).\n */\nexport function validateIndonesianPhoneNumber(phoneNumber: string): boolean {\n\tif (!phoneNumber || phoneNumber.trim().length === 0) return false;\n\tif (/[a-zA-Z]/.test(phoneNumber)) return false;\n\tconst cleaned = phoneNumber.replace(/\\D/g, \"\");\n\treturn /^\\d{9,12}$/.test(cleaned);\n}\n\n/** Payment ID field configuration for IDR (Indonesia, QRIS). */\nexport const IDR_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"phone\",\n\t\tlabel: \"PHONE_NUMBER\",\n\t\tplaceholder: IDR_PLACEHOLDER,\n\t\tdisplayLabel: \"Phone Number\",\n\t\tvalidate: validateIndonesianPhoneNumber,\n\t\tvalidationErrorMessage: IDR_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Indonesia (IDR). */\nexport const IDR_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Indonesia\",\n\tcurrency: CURRENCY.IDR,\n\tsymbolNative: \"Rp\",\n\tlocale: \"id-ID\",\n\tpaymentMethod: \"QRIS\",\n\tpaymentAddressName: \"PHONE_NUMBER\",\n\ttimezone: \"Asia/Jakarta\",\n\ttimezone_name: \"WIB\",\n\tflag: \"🇮🇩\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1ee-1f1e9.png\",\n\tphoneCode: \"+62\",\n\ttelegramSupportChannel: \"https://t.me/p2pmeindonesia\",\n\ttwitterUsername: \"p2pdotmeID\",\n\tsmsCountryCodes: [],\n\tprecision: 0,\n\tisAlpha: false,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const INR_PLACEHOLDER = \"merchant@upi\";\nexport const INR_VALIDATION_ERROR = \"Please enter a valid UPI ID (e.g., username@bankname)\";\n\n/**\n * Validates UPI ID format.\n * UPI ID format: username@bankname (e.g., john@paytm, user@ybl, 8658404239@kotak811)\n */\nexport function validateUPIId(upiId: string): boolean {\n\tif (!upiId || upiId.trim().length === 0) return false;\n\tconst upiRegex = /^[a-zA-Z0-9.\\-_]{2,256}@[a-zA-Z0-9]{2,64}$/;\n\treturn upiRegex.test(upiId.trim());\n}\n\n/** Payment ID field configuration for INR (India, UPI). */\nexport const INR_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"upi\",\n\t\tlabel: \"UPI_ID\",\n\t\tplaceholder: INR_PLACEHOLDER,\n\t\tdisplayLabel: \"UPI ID\",\n\t\tvalidate: validateUPIId,\n\t\tvalidationErrorMessage: INR_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for India (INR). */\nexport const INR_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"India\",\n\tcurrency: CURRENCY.INR,\n\tsymbolNative: \"₹\",\n\tlocale: \"en-IN\",\n\tpaymentMethod: \"UPI\",\n\tpaymentAddressName: \"UPI_ID\",\n\ttimezone: \"Asia/Kolkata\",\n\ttimezone_name: \"IST\",\n\tflag: \"🇮🇳\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1ee-1f1f3.png\",\n\tphoneCode: \"+91\",\n\ttelegramSupportChannel: \"https://t.me/P2Pdotme\",\n\ttwitterUsername: \"P2Pdotme\",\n\tsmsCountryCodes: [\"IN\"],\n\tprecision: 2,\n\tisAlpha: false,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const MEX_PLACEHOLDER = \"012345678901234567\";\nexport const MEX_VALIDATION_ERROR =\n\t\"Please enter a valid CLABE (18 digits), card number, or phone number\";\n\n/**\n * Validates Mexican payment IDs (CLABE, card number, or phone number).\n * CLABE: 18 digits. Card: 16 digits. Phone: 10 digits.\n */\nexport function validateMexicanPaymentId(paymentId: string): boolean {\n\tif (!paymentId || paymentId.trim().length === 0) return false;\n\n\tconst trimmed = paymentId.trim().replace(/\\D/g, \"\");\n\n\tif (/^\\d{18}$/.test(trimmed)) return true;\n\tif (/^\\d{16}$/.test(trimmed)) return true;\n\tif (/^\\d{10}$/.test(trimmed)) return true;\n\n\treturn false;\n}\n\n/** Payment ID field configuration for MEX (Mexico, SPEI). */\nexport const MEX_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"clabe\",\n\t\tlabel: \"CLABE_ID\",\n\t\tplaceholder: MEX_PLACEHOLDER,\n\t\tdisplayLabel: \"CLABE\",\n\t\tvalidate: validateMexicanPaymentId,\n\t\tvalidationErrorMessage: MEX_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Mexico (MEX). */\nexport const MEX_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Mexico\",\n\tcurrency: CURRENCY.MEX,\n\tinternationalFormat: \"MXN\",\n\tsymbolNative: \"Mx\",\n\tlocale: \"es-MX\",\n\tpaymentMethod: \"SPEI\",\n\tpaymentAddressName: \"CLABE_ID\",\n\ttimezone: \"America/Mexico_City\",\n\ttimezone_name: \"CST\",\n\tflag: \"🇲🇽\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1f2-1f1fd.png\",\n\tphoneCode: \"+52\",\n\ttelegramSupportChannel: \"https://t.me/p2pmemexico\",\n\ttwitterUsername: \"p2pmemexico\",\n\tsmsCountryCodes: [\"MX\"],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [\"PAY\"],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const NGN_PLACEHOLDER = \"0123456789\";\nexport const NGN_PLACEHOLDER_BANK = \"Bank Name\";\nexport const NGN_VALIDATION_ERROR = \"Please enter a valid 10-digit account number\";\n\n/**\n * Validates Nigerian bank account number (NUBAN format, 10 digits).\n */\nexport function validateNigerianAccountNumber(accountNumber: string): boolean {\n\tif (!accountNumber || accountNumber.trim().length === 0) return false;\n\tconst cleaned = accountNumber.trim().replace(/\\D/g, \"\");\n\treturn /^\\d{10}$/.test(cleaned);\n}\n\n/** Payment ID field configuration for NGN (Nigeria, NIP). */\nexport const NGN_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"account\",\n\t\tlabel: \"ACCOUNT_NUMBER\",\n\t\tplaceholder: NGN_PLACEHOLDER,\n\t\tdisplayLabel: \"Account Number\",\n\t\tvalidate: validateNigerianAccountNumber,\n\t\tvalidationErrorMessage: NGN_VALIDATION_ERROR,\n\t},\n\t{\n\t\tkey: \"bank-name\",\n\t\tlabel: \"BANK_NAME\",\n\t\tplaceholder: NGN_PLACEHOLDER_BANK,\n\t\tdisplayLabel: \"Bank Name\",\n\t\tvalidate: (v: string) => v.trim().length > 0,\n\t\tvalidationErrorMessage: NGN_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Nigeria (NGN). */\nexport const NGN_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Nigeria\",\n\tcurrency: CURRENCY.NGN,\n\tsymbolNative: \"₦\",\n\tlocale: \"en-NG\",\n\tpaymentMethod: \"NIP\",\n\tpaymentAddressName: \"ACCOUNT_NUMBER\",\n\ttimezone: \"Africa/Lagos\",\n\ttimezone_name: \"WAT\",\n\tflag: \"🇳🇬\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1f3-1f1ec.png\",\n\tphoneCode: \"+234\",\n\ttelegramSupportChannel: \"https://t.me/p2pmeNigeria\",\n\ttwitterUsername: \"p2pmeNigeria\",\n\tsmsCountryCodes: [\"NG\"],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\nimport { EUR_PLACEHOLDER, EUR_VALIDATION_ERROR, validateRevolutId } from \"./eur\";\n\nexport const USD_PLACEHOLDER = EUR_PLACEHOLDER;\nexport const USD_VALIDATION_ERROR = EUR_VALIDATION_ERROR;\n\n/** Payment ID field configuration for USD (Revolut USD). */\nexport const USD_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"revolut\",\n\t\tlabel: \"REVOLUT_ID\",\n\t\tplaceholder: USD_PLACEHOLDER,\n\t\tdisplayLabel: \"Revolut ID\",\n\t\tvalidate: validateRevolutId,\n\t\tvalidationErrorMessage: USD_VALIDATION_ERROR,\n\t},\n];\n\n/** Country option for Revolut USD. */\nexport const USD_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Revolut USD\",\n\tcurrency: CURRENCY.USD,\n\tsymbolNative: \"$\",\n\tlocale: \"en-US\",\n\tpaymentMethod: \"REVOLUT\",\n\tpaymentAddressName: \"REVOLUT_ID\",\n\ttimezone: \"America/New_York\",\n\ttimezone_name: \"EST\",\n\tflag: \"\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f310.png\",\n\tphoneCode: \"+1\",\n\ttelegramSupportChannel: \"https://t.me/P2Pdotme\",\n\ttwitterUsername: \"P2Pdotme\",\n\tsmsCountryCodes: [\"US\"],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [\"PAY\"],\n};\n","import { CURRENCY } from \"../currency\";\nimport type { CountryOption, PaymentIdFieldConfig } from \"../types\";\n\nexport const VEN_PLACEHOLDER = \"04121234567\";\nexport const VEN_PLACEHOLDER_RIF = \"V12345678\";\nexport const VEN_PLACEHOLDER_BANK = \"Banesco\";\n\nexport const VEN_VALIDATION_ERROR = \"Please enter a valid phone number (e.g., 04121234567)\";\nexport const VEN_VALIDATION_ERROR_RIF = \"Please enter a valid RIF (e.g., V12345678)\";\nexport const VEN_VALIDATION_ERROR_BANK = \"Please enter a bank name\";\n\n/**\n * Validates Venezuelan phone number for Pago Movil.\n * Format: 04XX-XXXXXXX (11 digits starting with 04).\n */\nexport function validateVenezuelanPhoneNumber(phoneNumber: string): boolean {\n\tif (!phoneNumber || phoneNumber.trim().length === 0) return false;\n\n\tconst cleaned = phoneNumber.trim().replace(/\\D/g, \"\");\n\n\tif (/^04\\d{9}$/.test(cleaned)) return true;\n\tif (/^4\\d{9}$/.test(cleaned)) return true;\n\n\treturn false;\n}\n\n/**\n * Validates Venezuelan RIF (Registro de Informacion Fiscal).\n * Format: One letter (J/V/E/G/C) followed by 7-9 digits.\n */\nexport function validateVenezuelanRif(rif: string): boolean {\n\tif (!rif || rif.trim().length === 0) return false;\n\tconst trimmed = rif.trim().toUpperCase();\n\treturn /^[JVEGC]\\d{7,9}$/.test(trimmed);\n}\n\n/** Payment ID field configuration for VEN (Venezuela, Pago Móvil). */\nexport const VEN_PAYMENT_FIELDS: PaymentIdFieldConfig[] = [\n\t{\n\t\tkey: \"phone\",\n\t\tlabel: \"PHONE_NUMBER\",\n\t\tplaceholder: VEN_PLACEHOLDER,\n\t\tdisplayLabel: \"Phone\",\n\t\tvalidate: validateVenezuelanPhoneNumber,\n\t\tvalidationErrorMessage: VEN_VALIDATION_ERROR,\n\t},\n\t{\n\t\tkey: \"rif\",\n\t\tlabel: \"RIF_LABEL\",\n\t\tplaceholder: VEN_PLACEHOLDER_RIF,\n\t\tdisplayLabel: \"RIF\",\n\t\tvalidate: validateVenezuelanRif,\n\t\tvalidationErrorMessage: VEN_VALIDATION_ERROR_RIF,\n\t},\n\t{\n\t\tkey: \"bank\",\n\t\tlabel: \"BANK_LABEL\",\n\t\tplaceholder: VEN_PLACEHOLDER_BANK,\n\t\tdisplayLabel: \"Banco\",\n\t\tvalidate: (v: string) => v.trim().length > 0,\n\t\tvalidationErrorMessage: VEN_VALIDATION_ERROR_BANK,\n\t},\n];\n\n/** Country option for Venezuela (VEN). */\nexport const VEN_COUNTRY_OPTION: CountryOption = {\n\tcountry: \"Venezuela\",\n\tcurrency: CURRENCY.VEN,\n\tinternationalFormat: \"VES\",\n\tsymbolNative: \"Bs\",\n\tlocale: \"es-VE\",\n\tpaymentMethod: \"PAGO_MOVIL\",\n\tpaymentAddressName: \"PAGO_MOVIL_DETAILS\",\n\ttimezone: \"America/Caracas\",\n\ttimezone_name: \"VET\",\n\tflag: \"🇻🇪\",\n\tflagUrl: \"https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f1fb-1f1ea.png\",\n\tphoneCode: \"+58\",\n\ttelegramSupportChannel: \"https://t.me/p2pmevenezuela\",\n\ttwitterUsername: \"p2pmevenezuela\",\n\tsmsCountryCodes: [\"VE\"],\n\tprecision: 2,\n\tisAlpha: true,\n\tdisabled: false,\n\tdisabledPaymentTypes: [],\n};\n","import {\n\tARS_COUNTRY_OPTION,\n\tBRL_COUNTRY_OPTION,\n\tCOP_COUNTRY_OPTION,\n\tEUR_COUNTRY_OPTION,\n\tIDR_COUNTRY_OPTION,\n\tINR_COUNTRY_OPTION,\n\tMEX_COUNTRY_OPTION,\n\tNGN_COUNTRY_OPTION,\n\tUSD_COUNTRY_OPTION,\n\tVEN_COUNTRY_OPTION,\n} from \"./currencies\";\nimport type { CountryOption } from \"./types\";\n\n/** All supported countries with their currency metadata, payment methods, and display config. */\nexport const COUNTRY_OPTIONS: readonly CountryOption[] = [\n\tINR_COUNTRY_OPTION,\n\tIDR_COUNTRY_OPTION,\n\tBRL_COUNTRY_OPTION,\n\tARS_COUNTRY_OPTION,\n\tMEX_COUNTRY_OPTION,\n\tVEN_COUNTRY_OPTION,\n\tNGN_COUNTRY_OPTION,\n\tCOP_COUNTRY_OPTION,\n\tEUR_COUNTRY_OPTION,\n\tUSD_COUNTRY_OPTION,\n];\n","import { err, ok, type Result } from \"neverthrow\";\nimport { COUNTRY_OPTIONS } from \"../country\";\nimport type { CurrencyCode } from \"../types\";\nimport { QRParserError, type QRParserErrorCode } from \"./errors\";\n\n/** Currencies that support QR parsing — derived from countries where PAY is not disabled. */\nexport const SUPPORTED_QR_CURRENCIES: readonly CurrencyCode[] = COUNTRY_OPTIONS.filter(\n\t(c) => !c.disabledPaymentTypes.includes(\"PAY\"),\n).map((c) => c.currency);\n\nexport type SupportedCurrency = (typeof SUPPORTED_QR_CURRENCIES)[number];\n\n/** Internal — options forwarded to per-currency parsers (today, only PIX uses them). */\nexport interface ParseQRConfig {\n\tproxyUrl?: string;\n\torderId?: string;\n}\n\n/** Single-object params for `parseQR`. */\nexport interface ParseQRParams {\n\treadonly qrData: string;\n\treadonly currency: SupportedCurrency;\n\t/** Exchange rate: 1 USDC = `sellPrice` fiat. */\n\treadonly sellPrice: number;\n\t/** Required for dynamic PIX (BRL) QRs to bypass CORS on the bank endpoint. */\n\treadonly proxyUrl?: string;\n\t/** Forwarded to `proxyUrl` for tracing / correlation. */\n\treadonly orderId?: string;\n}\n\nexport interface ParsedQR {\n\tpaymentAddress: string;\n\tamount?: {\n\t\tusdc: number;\n\t\tfiat: number;\n\t};\n}\n\nexport type ParseResult = Result<ParsedQR, QRParserError>;\n\nexport function success(data: ParsedQR): ParseResult {\n\treturn ok(data);\n}\n\nexport function failure(\n\tcode: QRParserErrorCode,\n\tmessage: string,\n\tcontext?: Record<string, unknown>,\n): ParseResult {\n\treturn err(new QRParserError(message, { code, context }));\n}\n","/**\n * Calculate CRC-16-CCITT-FALSE checksum.\n * Polynomial 0x1021, initial value 0xFFFF.\n * Used by EMVCo-compliant QR codes (PIX, MercadoPago).\n */\nexport function calculateCRC16(data: string): string {\n\tconst payload = `${data}6304`;\n\tconst polynomial = 0x1021;\n\tlet result = 0xffff;\n\n\tconst encoder = new TextEncoder();\n\tconst bytes = encoder.encode(payload);\n\n\tfor (let offset = 0; offset < bytes.length; offset++) {\n\t\tresult ^= bytes[offset] << 8;\n\t\tfor (let bitwise = 0; bitwise < 8; bitwise++) {\n\t\t\tresult <<= 1;\n\t\t\tif (result & 0x10000) {\n\t\t\t\tresult ^= polynomial;\n\t\t\t}\n\t\t\tresult &= 0xffff;\n\t\t}\n\t}\n\n\treturn result.toString(16).toUpperCase().padStart(4, \"0\");\n}\n\n/**\n * Verify CRC-16 checksum of an EMVCo QR string.\n * Expects the string to end with \"6304\" + 4 hex CRC digits.\n */\nexport function verifyCRC16(qrData: string): { valid: boolean; error?: string } {\n\tif (!qrData || qrData.length < 8) {\n\t\treturn { valid: false, error: \"QR data too short for CRC verification\" };\n\t}\n\n\tconst crcTagIndex = qrData.lastIndexOf(\"6304\");\n\tif (crcTagIndex === -1 || crcTagIndex + 8 !== qrData.length) {\n\t\treturn { valid: false, error: \"Missing or misplaced CRC tag (6304)\" };\n\t}\n\n\tconst providedCrc = qrData.substring(crcTagIndex + 4, crcTagIndex + 8);\n\tif (!/^[0-9A-Fa-f]{4}$/.test(providedCrc)) {\n\t\treturn { valid: false, error: \"Invalid CRC hex format\" };\n\t}\n\n\tconst dataBeforeCrc = qrData.substring(0, crcTagIndex);\n\tconst calculatedCrc = calculateCRC16(dataBeforeCrc);\n\n\tif (calculatedCrc !== providedCrc.toUpperCase()) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `CRC mismatch: expected ${calculatedCrc}, got ${providedCrc.toUpperCase()}`,\n\t\t};\n\t}\n\n\treturn { valid: true };\n}\n","/**\n * Parse a TLV (Tag-Length-Value) encoded string.\n * Tags are 2 digits, lengths are 2 digits (EMVCo standard).\n * Returns all parsed tag-value pairs. Stops gracefully on truncated data.\n */\nexport function parseTLV(data: string): { tag: string; value: string }[] {\n\tconst entries: { tag: string; value: string }[] = [];\n\tlet pos = 0;\n\n\twhile (pos + 4 <= data.length) {\n\t\tconst tag = data.substring(pos, pos + 2);\n\t\tconst lengthStr = data.substring(pos + 2, pos + 4);\n\n\t\tif (!/^[0-9]{2}$/.test(tag) || !/^[0-9]{2}$/.test(lengthStr)) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst length = parseInt(lengthStr, 10);\n\t\tif (pos + 4 + length > data.length) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst value = data.substring(pos + 4, pos + 4 + length);\n\t\tentries.push({ tag, value });\n\t\tpos += 4 + length;\n\t}\n\n\treturn entries;\n}\n\n/**\n * Extract specific tags from a TLV string.\n * Returns a record mapping tag IDs to their values.\n * Only includes tags present in the `tags` array.\n */\nexport function extractTags(data: string, tags: string[]): Record<string, string> {\n\tconst result: Record<string, string> = {};\n\tconst tagSet = new Set(tags);\n\n\tfor (const entry of parseTLV(data)) {\n\t\tif (tagSet.has(entry.tag)) {\n\t\t\tresult[entry.tag] = entry.value;\n\t\t}\n\t}\n\n\treturn result;\n}\n","import type { ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\nimport { verifyCRC16 } from \"../utils/crc16\";\nimport { extractTags } from \"../utils/tlv\";\n\nexport function parseMercadoPago(qrData: string, _sellPrice: number): ParseResult {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\n\tconst isARS = trimmed.includes(\"5303032\");\n\tconst isAR = trimmed.includes(\"5802AR\");\n\tif (!isARS && !isAR) {\n\t\treturn failure(\"INVALID_QR\", \"Not an ARS/Argentina QR code\");\n\t}\n\n\tconst crc = verifyCRC16(trimmed);\n\tif (!crc.valid) {\n\t\treturn failure(\"INVALID_QR\", \"Invalid QR checksum\");\n\t}\n\n\tconst tags = extractTags(trimmed, [\"59\"]);\n\tconst merchantName = tags[\"59\"] || \"Unknown\";\n\n\treturn success({ paymentAddress: merchantName });\n}\n","import { err, ok, type Result } from \"neverthrow\";\nimport { QRParserError, type QRParserErrorCode } from \"../errors\";\nimport type { ParsedQR, ParseQRConfig, ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\nimport { parseAmount } from \"../utils/amount\";\nimport { verifyCRC16 } from \"../utils/crc16\";\nimport { parseTLV } from \"../utils/tlv\";\n\nconst PIX_TAGS = {\n\tPAYLOAD_FORMAT: \"00\",\n\tPIX_KEY_INFO: \"26\",\n\tAMOUNT: \"54\",\n\tMERCHANT_NAME: \"59\",\n\tCRC: \"63\",\n} as const;\n\nfunction parsePIXKeyInfo(data: string): { pixKey: string | null; location: string | null } {\n\tconst result = { pixKey: null as string | null, location: null as string | null };\n\n\tfor (const entry of parseTLV(data)) {\n\t\tif (entry.tag === \"01\") {\n\t\t\tif (entry.value.includes(\"http\") || entry.value.includes(\"://\")) {\n\t\t\t\tresult.location = entry.value.startsWith(\"http\") ? entry.value : `https://${entry.value}`;\n\t\t\t} else {\n\t\t\t\tresult.pixKey = entry.value;\n\t\t\t}\n\t\t} else if (entry.tag === \"25\") {\n\t\t\tresult.location = entry.value.startsWith(\"http\") ? entry.value : `https://${entry.value}`;\n\t\t}\n\t}\n\n\treturn result;\n}\n\nfunction safeBase64Decode(base64String: string): string {\n\tif (typeof globalThis.atob === \"function\") {\n\t\treturn globalThis.atob(base64String);\n\t}\n\tthrow new Error(\"No base64 decoder available\");\n}\n\ninterface PIXJWTPayload {\n\tstatus?: string;\n\ttxid?: string;\n\tvalor?: { original?: string };\n\tcalendario?: { expiracao?: number };\n}\n\nfunction parseJWT(token: string): PIXJWTPayload | null {\n\ttry {\n\t\tconst parts = token.trim().split(\".\");\n\t\tif (parts.length !== 3 || !parts[0] || !parts[1] || !parts[2]) return null;\n\t\tconst json = safeBase64Decode(parts[1]);\n\t\treturn JSON.parse(json) as PIXJWTPayload;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction dynamicErr(\n\tcode: QRParserErrorCode,\n\tmessage: string,\n): Result<{ dynamicAmount?: string }, QRParserError> {\n\treturn err(new QRParserError(message, { code }));\n}\n\nasync function fetchDynamicData(\n\tlocation: string,\n\tproxyUrl: string,\n\torderId?: string,\n): Promise<Result<{ dynamicAmount?: string }, QRParserError>> {\n\ttry {\n\t\tconst url = new URL(`${proxyUrl}/pix`);\n\t\turl.searchParams.set(\"locationUrl\", location);\n\t\tif (orderId) {\n\t\t\turl.searchParams.set(\"orderId\", orderId);\n\t\t}\n\n\t\tconst response = await fetch(url, {\n\t\t\tmethod: \"GET\",\n\t\t\theaders: { Accept: \"*/*\" },\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\treturn dynamicErr(\"FETCH_FAILED\", `Proxy error: ${response.status} ${response.statusText}`);\n\t\t}\n\n\t\tconst jwtToken = await response.text();\n\t\tconst payload = parseJWT(jwtToken);\n\n\t\tif (!payload) {\n\t\t\treturn dynamicErr(\"FETCH_FAILED\", \"Failed to parse dynamic PIX response\");\n\t\t}\n\n\t\treturn ok({ dynamicAmount: payload.valor?.original });\n\t} catch (error) {\n\t\tconst msg = error instanceof Error ? error.message : \"Unknown error\";\n\t\treturn dynamicErr(\"FETCH_FAILED\", `Failed to fetch dynamic PIX data: ${msg}`);\n\t}\n}\n\nexport async function parsePIX(\n\tqrData: string,\n\tsellPrice: number,\n\tconfig: ParseQRConfig,\n): Promise<ParseResult> {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\n\tconst crc = verifyCRC16(trimmed);\n\tif (!crc.valid) {\n\t\treturn failure(\"INVALID_QR\", \"Invalid QR checksum\");\n\t}\n\n\tconst allTags: Record<string, string> = {};\n\tfor (const entry of parseTLV(trimmed)) {\n\t\tallTags[entry.tag] = entry.value;\n\t}\n\n\tif (!allTags[PIX_TAGS.PAYLOAD_FORMAT]) {\n\t\treturn failure(\"INVALID_QR\", \"Invalid PIX QR format\");\n\t}\n\n\tconst merchantName = allTags[PIX_TAGS.MERCHANT_NAME] || \"MERCHANT_NOT_FOUND\";\n\n\tlet dynamicAmount: string | undefined;\n\tconst pixKeyData = allTags[PIX_TAGS.PIX_KEY_INFO];\n\tif (pixKeyData) {\n\t\tconst { location } = parsePIXKeyInfo(pixKeyData);\n\t\tif (location) {\n\t\t\tif (!config.proxyUrl) {\n\t\t\t\treturn failure(\"FETCH_FAILED\", \"proxyUrl is required for dynamic PIX QR codes\");\n\t\t\t}\n\t\t\tconst dynamicResult = await fetchDynamicData(location, config.proxyUrl, config.orderId);\n\t\t\tif (dynamicResult.isErr()) {\n\t\t\t\treturn err(dynamicResult.error);\n\t\t\t}\n\t\t\tdynamicAmount = dynamicResult.value.dynamicAmount;\n\t\t}\n\t}\n\n\tconst fiatAmountStr = dynamicAmount || allTags[PIX_TAGS.AMOUNT];\n\tconst result: ParsedQR = { paymentAddress: merchantName };\n\n\tif (fiatAmountStr) {\n\t\tconst amount = parseAmount(fiatAmountStr, sellPrice);\n\t\tif (amount) {\n\t\t\tresult.amount = amount;\n\t\t}\n\t}\n\n\treturn success(result);\n}\n","/**\n * Parse a fiat amount string and convert to usdc using sellPrice.\n * Returns null if the amount is not parseable or <= 0.\n */\nexport function parseAmount(\n\tamountStr: string,\n\tsellPrice: number,\n): { usdc: number; fiat: number } | null {\n\tif (!amountStr || amountStr.trim() === \"\") return null;\n\n\tconst fiat = parseFloat(amountStr.trim());\n\tif (Number.isNaN(fiat) || fiat <= 0) return null;\n\n\treturn { usdc: fiat / sellPrice, fiat };\n}\n","import type { ParsedQR, ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\nimport { parseAmount } from \"../utils/amount\";\nimport { extractTags } from \"../utils/tlv\";\n\nconst QRIS_TAGS = { AMOUNT: \"54\", MERCHANT_NAME: \"59\" } as const;\n\nexport function parseQRIS(qrData: string, sellPrice: number): ParseResult {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\tconst tags = extractTags(trimmed, [QRIS_TAGS.AMOUNT, QRIS_TAGS.MERCHANT_NAME]);\n\n\tconst merchantName = tags[QRIS_TAGS.MERCHANT_NAME];\n\tif (!merchantName) {\n\t\treturn failure(\"INVALID_QR\", \"Missing merchant name\");\n\t}\n\n\tconst result: ParsedQR = { paymentAddress: merchantName };\n\n\tconst amountStr = tags[QRIS_TAGS.AMOUNT];\n\tif (amountStr) {\n\t\tconst amount = parseAmount(amountStr, sellPrice);\n\t\tif (!amount) {\n\t\t\treturn failure(\"INVALID_AMOUNT\", \"Invalid amount in QR\");\n\t\t}\n\t\tresult.amount = amount;\n\t}\n\n\treturn success(result);\n}\n","import type { ParsedQR, ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\nimport { parseAmount } from \"../utils/amount\";\n\nconst UPI_ID_REGEX = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+$/;\n\nexport function parseUPI(qrData: string, sellPrice: number): ParseResult {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\n\tlet paramString: string;\n\tif (trimmed.startsWith(\"upi://pay?\")) {\n\t\tparamString = trimmed.substring(10);\n\t} else if (trimmed.includes(\"?\")) {\n\t\tparamString = trimmed.split(\"?\")[1];\n\t} else {\n\t\tparamString = trimmed;\n\t}\n\n\tconst params = new URLSearchParams(paramString);\n\tconst pa = params.get(\"pa\");\n\n\tif (!pa) {\n\t\treturn failure(\"INVALID_QR\", \"Missing UPI payment address\");\n\t}\n\n\tif (!UPI_ID_REGEX.test(pa)) {\n\t\treturn failure(\"INVALID_QR\", \"Invalid UPI ID format\");\n\t}\n\n\tconst result: ParsedQR = { paymentAddress: pa };\n\n\tconst amountStr = params.get(\"am\");\n\tif (amountStr) {\n\t\tconst amount = parseAmount(amountStr, sellPrice);\n\t\tif (!amount) {\n\t\t\treturn failure(\"INVALID_AMOUNT\", \"Invalid amount in QR\");\n\t\t}\n\t\tresult.amount = amount;\n\t}\n\n\treturn success(result);\n}\n","import type { ParsedQR, ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\nimport { parseAmount } from \"../utils/amount\";\nimport { verifyCRC16 } from \"../utils/crc16\";\nimport { extractTags, parseTLV } from \"../utils/tlv\";\n\nconst NGN_TAGS = {\n\tAMOUNT: \"54\",\n\tCURRENCY: \"53\",\n\tCOUNTRY: \"58\",\n\tMERCHANT_NAME: \"59\",\n} as const;\n\nconst NGN_CURRENCY_CODE = \"566\";\nconst NIBSS_AID = \"NG.COM.NIBSSPLC.QR\";\n\nfunction isNQR(qrData: string): boolean {\n\tif (qrData.includes(NIBSS_AID)) return true;\n\tif (qrData.includes(`5303${NGN_CURRENCY_CODE}`)) return true;\n\tif (qrData.includes(\"5802NG\")) return true;\n\treturn false;\n}\n\nfunction parseEMVCoNQR(qrData: string, sellPrice: number): ParseResult {\n\tconst crc = verifyCRC16(qrData);\n\tif (!crc.valid) {\n\t\treturn failure(\"INVALID_QR\", \"Invalid QR checksum\");\n\t}\n\n\tif (!isNQR(qrData)) {\n\t\treturn failure(\"INVALID_QR\", \"Not a Nigerian (NQR) QR code\");\n\t}\n\n\tconst tags = extractTags(qrData, [NGN_TAGS.AMOUNT, NGN_TAGS.MERCHANT_NAME]);\n\n\tconst merchantName = tags[NGN_TAGS.MERCHANT_NAME];\n\tif (!merchantName) {\n\t\treturn failure(\"INVALID_QR\", \"Missing merchant name\");\n\t}\n\n\tconst result: ParsedQR = { paymentAddress: merchantName };\n\n\tconst amountStr = tags[NGN_TAGS.AMOUNT];\n\tif (amountStr) {\n\t\tconst amount = parseAmount(amountStr, sellPrice);\n\t\tif (!amount) {\n\t\t\treturn failure(\"INVALID_AMOUNT\", \"Invalid amount in QR\");\n\t\t}\n\t\tresult.amount = amount;\n\t}\n\n\treturn success(result);\n}\n\nfunction parseSPD(qrData: string, sellPrice: number): ParseResult {\n\t// Short Payment Descriptor (Czech spec). Seen in the wild for some\n\t// Nigerian account-based QRs: `SPD*1.0*ACC:<nuban>*AM:<amount>*MSG:<text>*`.\n\tconst parts = qrData.split(\"*\").filter((p) => p.length > 0);\n\tif (parts.length < 2 || parts[0] !== \"SPD\") {\n\t\treturn failure(\"INVALID_QR\", \"Not a valid SPD QR code\");\n\t}\n\n\tconst fields: Record<string, string> = {};\n\tfor (const part of parts.slice(2)) {\n\t\tconst colon = part.indexOf(\":\");\n\t\tif (colon === -1) continue;\n\t\tfields[part.substring(0, colon).toUpperCase()] = part.substring(colon + 1);\n\t}\n\n\tconst account = fields.ACC;\n\tif (!account) {\n\t\treturn failure(\"INVALID_QR\", \"Missing ACC field in SPD QR\");\n\t}\n\n\tconst result: ParsedQR = { paymentAddress: account };\n\n\tconst amountStr = fields.AM;\n\tif (amountStr) {\n\t\tconst amount = parseAmount(amountStr.replace(/,/g, \"\"), sellPrice);\n\t\tif (!amount) {\n\t\t\treturn failure(\"INVALID_AMOUNT\", \"Invalid amount in QR\");\n\t\t}\n\t\tresult.amount = amount;\n\t}\n\n\treturn success(result);\n}\n\n/**\n * Parses a Nigerian QR code. Supports NIBSS NQR (EMVCo MPM with AID\n * `NG.COM.NIBSSPLC.QR`) and the SPD `SPD*1.0*ACC:...*AM:...*` format.\n */\nexport function parseNGN(qrData: string, sellPrice: number): ParseResult {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\n\tif (trimmed.startsWith(\"SPD*\")) {\n\t\treturn parseSPD(trimmed, sellPrice);\n\t}\n\n\t// Sanity-check that this looks like EMVCo TLV before CRC-ing.\n\tif (parseTLV(trimmed).length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"Not a valid Nigerian QR code\");\n\t}\n\n\treturn parseEMVCoNQR(trimmed, sellPrice);\n}\n","import type { ParseResult } from \"../types\";\nimport { failure, success } from \"../types\";\n\nexport function parsePagoMovil(qrData: string, _sellPrice: number): ParseResult {\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tconst trimmed = qrData.trim();\n\n\tconst qIdx = trimmed.indexOf(\"?\");\n\tif (qIdx === -1) {\n\t\treturn failure(\"INVALID_QR\", \"Not a valid Venezuelan QR code\");\n\t}\n\n\tconst payload = trimmed.substring(0, qIdx);\n\n\tif (!payload || !/^[A-Za-z0-9+/=]+$/.test(payload)) {\n\t\treturn failure(\"INVALID_QR\", \"Not a valid Venezuelan QR code\");\n\t}\n\n\treturn success({ paymentAddress: trimmed });\n}\n","import { CURRENCY } from \"../country\";\nimport { parseMercadoPago } from \"./parsers/ars\";\nimport { parsePIX } from \"./parsers/brl\";\nimport { parseQRIS } from \"./parsers/idr\";\nimport { parseUPI } from \"./parsers/inr\";\nimport { parseNGN } from \"./parsers/ngn\";\nimport { parsePagoMovil } from \"./parsers/ven\";\nimport type { ParseQRParams, ParseResult } from \"./types\";\nimport { failure } from \"./types\";\n\n/**\n * Parses a QR string for the given currency and returns the extracted payment data.\n *\n * This dispatcher is `async` because dynamic PIX (BRL) QRs store the amount\n * behind a location URL pointing at the issuing bank's PIX endpoint. The SDK\n * resolves that URL via a CORS-bypassing proxy (see `proxyUrl`), which returns\n * a signed JWT whose `valor.original` field holds the amount. All other parsers\n * (UPI, QRIS, MercadoPago, PagoMovil) and static PIX are synchronous and resolve\n * immediately.\n */\nexport async function parseQR(params: ParseQRParams): Promise<ParseResult> {\n\tconst { qrData, currency, sellPrice, proxyUrl, orderId } = params;\n\n\tif (!qrData || typeof qrData !== \"string\" || qrData.trim().length === 0) {\n\t\treturn failure(\"INVALID_QR\", \"QR data is empty or invalid\");\n\t}\n\n\tswitch (currency) {\n\t\tcase CURRENCY.INR:\n\t\t\treturn parseUPI(qrData, sellPrice);\n\t\tcase CURRENCY.IDR:\n\t\t\treturn parseQRIS(qrData, sellPrice);\n\t\tcase CURRENCY.BRL:\n\t\t\treturn parsePIX(qrData, sellPrice, { proxyUrl, orderId });\n\t\tcase CURRENCY.ARS:\n\t\t\treturn parseMercadoPago(qrData, sellPrice);\n\t\tcase CURRENCY.VEN:\n\t\t\treturn parsePagoMovil(qrData, sellPrice);\n\t\tcase CURRENCY.NGN:\n\t\t\treturn parseNGN(qrData, sellPrice);\n\t\tdefault:\n\t\t\treturn failure(\"INVALID_CURRENCY\", `Currency \"${currency}\" is not supported`);\n\t}\n}\n"],"mappings":";;;;;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QAAQ,UAAU,GAAG,IAAI;AAEzC,MAAI,CAAC,WAAW,CAAC,oBAAoB,KAAK,OAAO,GAAG;AACnD,WAAO,QAAQ,cAAc,gCAAgC;AAAA,EAC9D;AAEA,SAAO,QAAQ,EAAE,gBAAgB,QAAQ,CAAC;AAC3C;;;ACFA,eAAsB,QAAQ,QAA6C;AAC1E,QAAM,EAAE,QAAQ,UAAU,WAAW,UAAU,QAAQ,IAAI;AAE3D,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,OAAO,KAAK,EAAE,WAAW,GAAG;AACxE,WAAO,QAAQ,cAAc,6BAA6B;AAAA,EAC3D;AAEA,UAAQ,UAAU;AAAA,IACjB,KAAK,SAAS;AACb,aAAO,SAAS,QAAQ,SAAS;AAAA,IAClC,KAAK,SAAS;AACb,aAAO,UAAU,QAAQ,SAAS;AAAA,IACnC,KAAK,SAAS;AACb,aAAO,SAAS,QAAQ,WAAW,EAAE,UAAU,QAAQ,CAAC;AAAA,IACzD,KAAK,SAAS;AACb,aAAO,iBAAiB,QAAQ,SAAS;AAAA,IAC1C,KAAK,SAAS;AACb,aAAO,eAAe,QAAQ,SAAS;AAAA,IACxC,KAAK,SAAS;AACb,aAAO,SAAS,QAAQ,SAAS;AAAA,IAClC;AACC,aAAO,QAAQ,oBAAoB,aAAa,QAAQ,oBAAoB;AAAA,EAC9E;AACD;","names":["import_neverthrow"]}
@@ -201,7 +201,7 @@ var NGN_COUNTRY_OPTION = {
201
201
  precision: 2,
202
202
  isAlpha: true,
203
203
  disabled: false,
204
- disabledPaymentTypes: ["PAY"]
204
+ disabledPaymentTypes: []
205
205
  };
206
206
 
207
207
  // src/country/currencies/usd.ts
@@ -548,6 +548,85 @@ function parseUPI(qrData, sellPrice) {
548
548
  return success(result);
549
549
  }
550
550
 
551
+ // src/qr-parsers/parsers/ngn.ts
552
+ var NGN_TAGS = {
553
+ AMOUNT: "54",
554
+ CURRENCY: "53",
555
+ COUNTRY: "58",
556
+ MERCHANT_NAME: "59"
557
+ };
558
+ var NGN_CURRENCY_CODE = "566";
559
+ var NIBSS_AID = "NG.COM.NIBSSPLC.QR";
560
+ function isNQR(qrData) {
561
+ if (qrData.includes(NIBSS_AID)) return true;
562
+ if (qrData.includes(`5303${NGN_CURRENCY_CODE}`)) return true;
563
+ if (qrData.includes("5802NG")) return true;
564
+ return false;
565
+ }
566
+ function parseEMVCoNQR(qrData, sellPrice) {
567
+ const crc = verifyCRC16(qrData);
568
+ if (!crc.valid) {
569
+ return failure("INVALID_QR", "Invalid QR checksum");
570
+ }
571
+ if (!isNQR(qrData)) {
572
+ return failure("INVALID_QR", "Not a Nigerian (NQR) QR code");
573
+ }
574
+ const tags = extractTags(qrData, [NGN_TAGS.AMOUNT, NGN_TAGS.MERCHANT_NAME]);
575
+ const merchantName = tags[NGN_TAGS.MERCHANT_NAME];
576
+ if (!merchantName) {
577
+ return failure("INVALID_QR", "Missing merchant name");
578
+ }
579
+ const result = { paymentAddress: merchantName };
580
+ const amountStr = tags[NGN_TAGS.AMOUNT];
581
+ if (amountStr) {
582
+ const amount = parseAmount(amountStr, sellPrice);
583
+ if (!amount) {
584
+ return failure("INVALID_AMOUNT", "Invalid amount in QR");
585
+ }
586
+ result.amount = amount;
587
+ }
588
+ return success(result);
589
+ }
590
+ function parseSPD(qrData, sellPrice) {
591
+ const parts = qrData.split("*").filter((p) => p.length > 0);
592
+ if (parts.length < 2 || parts[0] !== "SPD") {
593
+ return failure("INVALID_QR", "Not a valid SPD QR code");
594
+ }
595
+ const fields = {};
596
+ for (const part of parts.slice(2)) {
597
+ const colon = part.indexOf(":");
598
+ if (colon === -1) continue;
599
+ fields[part.substring(0, colon).toUpperCase()] = part.substring(colon + 1);
600
+ }
601
+ const account = fields.ACC;
602
+ if (!account) {
603
+ return failure("INVALID_QR", "Missing ACC field in SPD QR");
604
+ }
605
+ const result = { paymentAddress: account };
606
+ const amountStr = fields.AM;
607
+ if (amountStr) {
608
+ const amount = parseAmount(amountStr.replace(/,/g, ""), sellPrice);
609
+ if (!amount) {
610
+ return failure("INVALID_AMOUNT", "Invalid amount in QR");
611
+ }
612
+ result.amount = amount;
613
+ }
614
+ return success(result);
615
+ }
616
+ function parseNGN(qrData, sellPrice) {
617
+ if (!qrData || typeof qrData !== "string" || qrData.trim().length === 0) {
618
+ return failure("INVALID_QR", "QR data is empty or invalid");
619
+ }
620
+ const trimmed = qrData.trim();
621
+ if (trimmed.startsWith("SPD*")) {
622
+ return parseSPD(trimmed, sellPrice);
623
+ }
624
+ if (parseTLV(trimmed).length === 0) {
625
+ return failure("INVALID_QR", "Not a valid Nigerian QR code");
626
+ }
627
+ return parseEMVCoNQR(trimmed, sellPrice);
628
+ }
629
+
551
630
  // src/qr-parsers/parsers/ven.ts
552
631
  function parsePagoMovil(qrData, _sellPrice) {
553
632
  if (!qrData || typeof qrData !== "string" || qrData.trim().length === 0) {
@@ -582,6 +661,8 @@ async function parseQR(params) {
582
661
  return parseMercadoPago(qrData, sellPrice);
583
662
  case CURRENCY.VEN:
584
663
  return parsePagoMovil(qrData, sellPrice);
664
+ case CURRENCY.NGN:
665
+ return parseNGN(qrData, sellPrice);
585
666
  default:
586
667
  return failure("INVALID_CURRENCY", `Currency "${currency}" is not supported`);
587
668
  }