@p2pdotme/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -0
- package/dist/fraud-engine.cjs +598 -0
- package/dist/fraud-engine.cjs.map +1 -0
- package/dist/fraud-engine.d.cts +194 -0
- package/dist/fraud-engine.d.ts +194 -0
- package/dist/fraud-engine.mjs +549 -0
- package/dist/fraud-engine.mjs.map +1 -0
- package/dist/index.cjs +75 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.mjs +46 -0
- package/dist/index.mjs.map +1 -0
- package/dist/order-routing.cjs +882 -0
- package/dist/order-routing.cjs.map +1 -0
- package/dist/order-routing.d.cts +68 -0
- package/dist/order-routing.d.ts +68 -0
- package/dist/order-routing.mjs +854 -0
- package/dist/order-routing.mjs.map +1 -0
- package/dist/payload.cjs +3164 -0
- package/dist/payload.cjs.map +1 -0
- package/dist/payload.d.cts +162 -0
- package/dist/payload.d.ts +162 -0
- package/dist/payload.mjs +3120 -0
- package/dist/payload.mjs.map +1 -0
- package/dist/profile.cjs +695 -0
- package/dist/profile.cjs.map +1 -0
- package/dist/profile.d.cts +133 -0
- package/dist/profile.d.ts +133 -0
- package/dist/profile.mjs +667 -0
- package/dist/profile.mjs.map +1 -0
- package/dist/qr-parsers.cjs +366 -0
- package/dist/qr-parsers.cjs.map +1 -0
- package/dist/qr-parsers.d.cts +41 -0
- package/dist/qr-parsers.d.ts +41 -0
- package/dist/qr-parsers.mjs +338 -0
- package/dist/qr-parsers.mjs.map +1 -0
- package/dist/react.cjs +4803 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +511 -0
- package/dist/react.d.ts +511 -0
- package/dist/react.mjs +4759 -0
- package/dist/react.mjs.map +1 -0
- package/dist/zkkyc.cjs +868 -0
- package/dist/zkkyc.cjs.map +1 -0
- package/dist/zkkyc.d.cts +230 -0
- package/dist/zkkyc.d.ts +230 -0
- package/dist/zkkyc.mjs +824 -0
- package/dist/zkkyc.mjs.map +1 -0
- package/package.json +130 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/contracts/abis/index.ts","../src/contracts/abis/order-flow-facet.ts","../src/contracts/abis/p2p-config-facet.ts","../src/contracts/abis/reputation-manager.ts","../src/contracts/order-flow/index.ts","../src/validation/errors.ts","../src/validation/schemas.ts","../src/order-routing/validation.ts","../src/contracts/p2p-config/index.ts","../src/profile/errors.ts","../src/profile/validation.ts","../src/contracts/reputation-manager/writes.ts","../src/zkkyc/validation.ts","../src/contracts/tx-limits/index.ts","../src/contracts/usdc/index.ts","../src/profile/contracts/actions.ts","../src/profile/client.ts"],"sourcesContent":["import { erc20Abi } from \"viem\";\nimport { orderFlowFacetAbi } from \"./order-flow-facet\";\nimport { p2pConfigFacetAbi } from \"./p2p-config-facet\";\nimport { reputationManagerAbi } from \"./reputation-manager\";\n\nconst DIAMOND_ABI = [...orderFlowFacetAbi, ...p2pConfigFacetAbi] as const;\n\nexport const ABIS = {\n\tDIAMOND: DIAMOND_ABI,\n\tFACETS: {\n\t\tORDER_FLOW: orderFlowFacetAbi,\n\t\tCONFIG: p2pConfigFacetAbi,\n\t},\n\tEXTERNAL: {\n\t\tUSDC: erc20Abi,\n\t\tREPUTATION_MANAGER: reputationManagerAbi,\n\t},\n} as const;\n","export const orderFlowFacetAbi = [\n\t{\n\t\tinputs: [\n\t\t\t{ internalType: \"uint256\", name: \"circleId\", type: \"uint256\" },\n\t\t\t{ internalType: \"uint256\", name: \"assignUpto\", type: \"uint256\" },\n\t\t\t{ internalType: \"bytes32\", name: \"currency\", type: \"bytes32\" },\n\t\t\t{ internalType: \"address\", name: \"user\", type: \"address\" },\n\t\t\t{ internalType: \"uint256\", name: \"usdtAmount\", type: \"uint256\" },\n\t\t\t{ internalType: \"uint256\", name: \"fiatAmount\", type: \"uint256\" },\n\t\t\t{ internalType: \"int256\", name: \"orderType\", type: \"int256\" },\n\t\t\t{ internalType: \"uint256\", name: \"preferredPCConfigId\", type: \"uint256\" },\n\t\t],\n\t\tname: \"getAssignableMerchantsFromCircle\",\n\t\toutputs: [{ internalType: \"address[]\", name: \"\", type: \"address[]\" }],\n\t\tstateMutability: \"view\",\n\t\ttype: \"function\",\n\t},\n\t{\n\t\tinputs: [\n\t\t\t{ internalType: \"address\", name: \"_user\", type: \"address\" },\n\t\t\t{ internalType: \"bytes32\", name: \"_nativeCurrency\", type: \"bytes32\" },\n\t\t],\n\t\tname: \"userTxLimit\",\n\t\toutputs: [\n\t\t\t{ internalType: \"uint256\", name: \"\", type: \"uint256\" },\n\t\t\t{ internalType: \"uint256\", name: \"\", type: \"uint256\" },\n\t\t],\n\t\tstateMutability: \"view\",\n\t\ttype: \"function\",\n\t},\n] as const;\n","export const p2pConfigFacetAbi = [\n\t{\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tinternalType: \"bytes32\",\n\t\t\t\tname: \"_currency\",\n\t\t\t\ttype: \"bytes32\",\n\t\t\t},\n\t\t],\n\t\tname: \"getPriceConfig\",\n\t\toutputs: [\n\t\t\t{\n\t\t\t\tcomponents: [\n\t\t\t\t\t{\n\t\t\t\t\t\tinternalType: \"uint256\",\n\t\t\t\t\t\tname: \"buyPrice\",\n\t\t\t\t\t\ttype: \"uint256\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tinternalType: \"uint256\",\n\t\t\t\t\t\tname: \"sellPrice\",\n\t\t\t\t\t\ttype: \"uint256\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tinternalType: \"int256\",\n\t\t\t\t\t\tname: \"buyPriceOffset\",\n\t\t\t\t\t\ttype: \"int256\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tinternalType: \"uint256\",\n\t\t\t\t\t\tname: \"baseSpread\",\n\t\t\t\t\t\ttype: \"uint256\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tinternalType: \"struct P2pConfigStorage.PriceConfig\",\n\t\t\t\tname: \"\",\n\t\t\t\ttype: \"tuple\",\n\t\t\t},\n\t\t],\n\t\tstateMutability: \"view\",\n\t\ttype: \"function\",\n\t},\n\t{\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tinternalType: \"bytes32\",\n\t\t\t\tname: \"_nativeCurrency\",\n\t\t\t\ttype: \"bytes32\",\n\t\t\t},\n\t\t],\n\t\tname: \"getRpPerUsdtLimitRational\",\n\t\toutputs: [\n\t\t\t{\n\t\t\t\tinternalType: \"uint256\",\n\t\t\t\tname: \"numerator\",\n\t\t\t\ttype: \"uint256\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tinternalType: \"uint256\",\n\t\t\t\tname: \"denominator\",\n\t\t\t\ttype: \"uint256\",\n\t\t\t},\n\t\t],\n\t\tstateMutability: \"view\",\n\t\ttype: \"function\",\n\t},\n] as const;\n","export const reputationManagerAbi = [\n\t{\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tinternalType: \"string\",\n\t\t\t\tname: \"_socialName\",\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tcomponents: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcomponents: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"string\",\n\t\t\t\t\t\t\t\tname: \"provider\",\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"string\",\n\t\t\t\t\t\t\t\tname: \"parameters\",\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"string\",\n\t\t\t\t\t\t\t\tname: \"context\",\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tinternalType: \"struct IReclaimSDK.ClaimInfo\",\n\t\t\t\t\t\tname: \"claimInfo\",\n\t\t\t\t\t\ttype: \"tuple\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tcomponents: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcomponents: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tinternalType: \"bytes32\",\n\t\t\t\t\t\t\t\t\t\tname: \"identifier\",\n\t\t\t\t\t\t\t\t\t\ttype: \"bytes32\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tinternalType: \"address\",\n\t\t\t\t\t\t\t\t\t\tname: \"owner\",\n\t\t\t\t\t\t\t\t\t\ttype: \"address\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tinternalType: \"uint32\",\n\t\t\t\t\t\t\t\t\t\tname: \"timestampS\",\n\t\t\t\t\t\t\t\t\t\ttype: \"uint32\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tinternalType: \"uint32\",\n\t\t\t\t\t\t\t\t\t\tname: \"epoch\",\n\t\t\t\t\t\t\t\t\t\ttype: \"uint32\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tinternalType: \"struct IReclaimSDK.CompleteClaimData\",\n\t\t\t\t\t\t\t\tname: \"claim\",\n\t\t\t\t\t\t\t\ttype: \"tuple\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"bytes[]\",\n\t\t\t\t\t\t\t\tname: \"signatures\",\n\t\t\t\t\t\t\t\ttype: \"bytes[]\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tinternalType: \"struct IReclaimSDK.SignedClaim\",\n\t\t\t\t\t\tname: \"signedClaim\",\n\t\t\t\t\t\ttype: \"tuple\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tinternalType: \"struct IReclaimSDK.Proof[]\",\n\t\t\t\tname: \"proofs\",\n\t\t\t\ttype: \"tuple[]\",\n\t\t\t},\n\t\t],\n\t\tname: \"socialVerify\",\n\t\toutputs: [],\n\t\tstateMutability: \"nonpayable\",\n\t\ttype: \"function\",\n\t},\n\t{\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tinternalType: \"uint256\",\n\t\t\t\tname: \"nullifierSeed\",\n\t\t\t\ttype: \"uint256\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tinternalType: \"uint256\",\n\t\t\t\tname: \"nullifier\",\n\t\t\t\ttype: \"uint256\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tinternalType: \"uint256\",\n\t\t\t\tname: \"timestamp\",\n\t\t\t\ttype: \"uint256\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tinternalType: \"uint256\",\n\t\t\t\tname: \"signal\",\n\t\t\t\ttype: \"uint256\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tinternalType: \"uint256[4]\",\n\t\t\t\tname: \"revealArray\",\n\t\t\t\ttype: \"uint256[4]\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tinternalType: \"uint256[8]\",\n\t\t\t\tname: \"groth16Proof\",\n\t\t\t\ttype: \"uint256[8]\",\n\t\t\t},\n\t\t],\n\t\tname: \"submitAnonAadharProof\",\n\t\toutputs: [],\n\t\tstateMutability: \"nonpayable\",\n\t\ttype: \"function\",\n\t},\n\t{\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tcomponents: [\n\t\t\t\t\t{\n\t\t\t\t\t\tinternalType: \"bytes32\",\n\t\t\t\t\t\tname: \"version\",\n\t\t\t\t\t\ttype: \"bytes32\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tcomponents: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"bytes32\",\n\t\t\t\t\t\t\t\tname: \"vkeyHash\",\n\t\t\t\t\t\t\t\ttype: \"bytes32\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"bytes\",\n\t\t\t\t\t\t\t\tname: \"proof\",\n\t\t\t\t\t\t\t\ttype: \"bytes\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"bytes32[]\",\n\t\t\t\t\t\t\t\tname: \"publicInputs\",\n\t\t\t\t\t\t\t\ttype: \"bytes32[]\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tinternalType: \"struct ProofVerificationData\",\n\t\t\t\t\t\tname: \"proofVerificationData\",\n\t\t\t\t\t\ttype: \"tuple\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tinternalType: \"bytes\",\n\t\t\t\t\t\tname: \"committedInputs\",\n\t\t\t\t\t\ttype: \"bytes\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tcomponents: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"uint256\",\n\t\t\t\t\t\t\t\tname: \"validityPeriodInSeconds\",\n\t\t\t\t\t\t\t\ttype: \"uint256\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"string\",\n\t\t\t\t\t\t\t\tname: \"domain\",\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"string\",\n\t\t\t\t\t\t\t\tname: \"scope\",\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tinternalType: \"bool\",\n\t\t\t\t\t\t\t\tname: \"devMode\",\n\t\t\t\t\t\t\t\ttype: \"bool\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tinternalType: \"struct ServiceConfig\",\n\t\t\t\t\t\tname: \"serviceConfig\",\n\t\t\t\t\t\ttype: \"tuple\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tinternalType: \"struct ProofVerificationParams\",\n\t\t\t\tname: \"params\",\n\t\t\t\ttype: \"tuple\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tinternalType: \"bool\",\n\t\t\t\tname: \"isIDCard\",\n\t\t\t\ttype: \"bool\",\n\t\t\t},\n\t\t],\n\t\tname: \"zkPassportRegister\",\n\t\toutputs: [],\n\t\tstateMutability: \"nonpayable\",\n\t\ttype: \"function\",\n\t},\n] as const;\n","import { ResultAsync } from \"neverthrow\";\nimport type { Address } from \"viem\";\nimport { noopLogger } from \"../../lib\";\nimport { OrderRoutingError } from \"../../order-routing/errors\";\nimport type { CheckCircleEligibilityParams, Logger } from \"../../order-routing/types\";\nimport { ZodCheckCircleEligibilityParamsSchema } from \"../../order-routing/validation\";\nimport type { PublicClientLike } from \"../../types\";\nimport { validate } from \"../../validation\";\nimport { ABIS } from \"../abis\";\n\n/** Checks on-chain eligibility for a given circle by reading assignable merchants. */\nexport function checkCircleEligibility(\n\tpublicClient: PublicClientLike,\n\tcontractAddress: Address,\n\tparams: CheckCircleEligibilityParams,\n\tlogger: Logger = noopLogger,\n): ResultAsync<boolean, OrderRoutingError> {\n\treturn validate(\n\t\tZodCheckCircleEligibilityParamsSchema,\n\t\tparams,\n\t\t(message, cause, d) =>\n\t\t\tnew OrderRoutingError(message, { code: \"VALIDATION_ERROR\", cause, context: { data: d } }),\n\t)\n\t\t.asyncAndThen((validated) => {\n\t\t\tlogger.debug(\"checking on-chain eligibility\", {\n\t\t\t\tcircleId: String(validated.circleId),\n\t\t\t\tcontractAddress,\n\t\t\t});\n\n\t\t\treturn ResultAsync.fromPromise(\n\t\t\t\tpublicClient.readContract({\n\t\t\t\t\taddress: contractAddress,\n\t\t\t\t\tabi: ABIS.FACETS.ORDER_FLOW,\n\t\t\t\t\tfunctionName: \"getAssignableMerchantsFromCircle\",\n\t\t\t\t\targs: [\n\t\t\t\t\t\tvalidated.circleId,\n\t\t\t\t\t\t1n,\n\t\t\t\t\t\tvalidated.currency,\n\t\t\t\t\t\tvalidated.user as Address,\n\t\t\t\t\t\tvalidated.usdtAmount,\n\t\t\t\t\t\tvalidated.fiatAmount,\n\t\t\t\t\t\tvalidated.orderType,\n\t\t\t\t\t\tvalidated.preferredPCConfigId,\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\t(error) =>\n\t\t\t\t\tnew OrderRoutingError(\"Eligibility check failed\", {\n\t\t\t\t\t\tcode: \"CONTRACT_READ_ERROR\",\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tcontext: { circleId: String(params.circleId) },\n\t\t\t\t\t}),\n\t\t\t);\n\t\t})\n\t\t.map((merchants) => {\n\t\t\tconst arr = merchants as readonly Address[];\n\t\t\tconst eligible = arr.length >= 1;\n\t\t\tlogger.debug(\"eligibility check result\", {\n\t\t\t\tcircleId: String(params.circleId),\n\t\t\t\tassignableMerchants: arr.length,\n\t\t\t\teligible,\n\t\t\t});\n\t\t\treturn eligible;\n\t\t});\n}\n","export class SdkError<TCode extends string = string> extends Error {\n\treadonly code: TCode;\n\treadonly cause?: unknown;\n\treadonly context?: Record<string, unknown>;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\tcode: TCode;\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 = \"SdkError\";\n\t\tthis.code = options.code;\n\t\tthis.cause = options.cause;\n\t\tthis.context = options.context;\n\t}\n}\n","import { err, ok, type Result } from \"neverthrow\";\nimport { isAddress } from \"viem\";\nimport { z } from \"zod\";\n\nexport const ZodAddressSchema = z\n\t.string()\n\t.refine((s) => isAddress(s), { message: \"Invalid Ethereum address\" });\n\nexport const ZodCurrencySchema = z.enum([\n\t\"IDR\",\n\t\"INR\",\n\t\"BRL\",\n\t\"ARS\",\n\t\"MEX\",\n\t\"VEN\",\n\t\"EUR\",\n\t\"NGN\",\n\t\"USD\",\n]);\n\nexport type CurrencyType = z.infer<typeof ZodCurrencySchema>;\n\nexport function validate<S extends z.ZodType, E>(\n\tschema: S,\n\tdata: unknown,\n\ttoError: (message: string, cause: unknown, data: unknown) => E,\n): Result<z.infer<S>, E> {\n\tconst result = schema.safeParse(data);\n\tif (result.success) {\n\t\treturn ok(result.data as z.infer<S>);\n\t}\n\treturn err(toError(z.prettifyError(result.error), result.error, data));\n}\n","import { z } from \"zod\";\nimport { ZodAddressSchema } from \"../validation/schemas\";\n\n// ── Circle schemas ──────────────────────────────────────────────────────\n\nexport const ZodCircleScoreStateSchema = z.object({\n\tactiveMerchantsCount: z.coerce.number(),\n});\n\nexport const ZodCircleMetricsForRoutingSchema = z.object({\n\tcircleScore: z.coerce.number(),\n\tcircleStatus: z.string(),\n\tscoreState: ZodCircleScoreStateSchema,\n});\n\nexport const ZodCircleForRoutingSchema = z.object({\n\tcircleId: z.string(),\n\tcurrency: z.string(),\n\tmetrics: ZodCircleMetricsForRoutingSchema,\n});\n\nexport const ZodCirclesForRoutingResponseSchema = z.object({\n\tcircles: z.array(ZodCircleForRoutingSchema),\n});\n\n// ── Eligibility check schema ────────────────────────────────────────────\n\nexport const ZodCheckCircleEligibilityParamsSchema = z.object({\n\tcircleId: z.bigint(),\n\tcurrency: z.string(),\n\tuser: ZodAddressSchema,\n\tusdtAmount: z.bigint(),\n\tfiatAmount: z.bigint(),\n\torderType: z.bigint(),\n\tpreferredPCConfigId: z.bigint(),\n});\n\n// ── Select circle schema ────────────────────────────────────────────────\n\nexport const ZodSelectCircleParamsSchema = z.object({\n\tcurrency: z.string().min(1),\n\tuser: ZodAddressSchema,\n\tusdtAmount: z.bigint(),\n\tfiatAmount: z.bigint(),\n\torderType: z.bigint(),\n\tpreferredPCConfigId: z.bigint(),\n});\n","import { ResultAsync } from \"neverthrow\";\nimport { type Address, stringToHex } from \"viem\";\nimport { ProfileError } from \"../../profile/errors\";\nimport type { PriceConfig } from \"../../profile/types\";\nimport type { PriceConfigParams } from \"../../profile/validation\";\nimport { ZodPriceConfigParamsSchema } from \"../../profile/validation\";\nimport type { PublicClientLike } from \"../../types\";\nimport { validate } from \"../../validation\";\nimport { ABIS } from \"../abis\";\n\n/** Reads the price config (buy/sell prices) for a given currency. */\nexport function getPriceConfig(\n\tpublicClient: PublicClientLike,\n\tdiamondAddress: Address,\n\tparams: PriceConfigParams,\n): ResultAsync<PriceConfig, ProfileError> {\n\treturn validate(\n\t\tZodPriceConfigParamsSchema,\n\t\tparams,\n\t\t(message, cause, data) =>\n\t\t\tnew ProfileError(message, {\n\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\tcause,\n\t\t\t\tcontext: { params: data },\n\t\t\t}),\n\t).asyncAndThen((validated) =>\n\t\tResultAsync.fromPromise(\n\t\t\tpublicClient.readContract({\n\t\t\t\taddress: diamondAddress,\n\t\t\t\tabi: ABIS.FACETS.CONFIG,\n\t\t\t\tfunctionName: \"getPriceConfig\",\n\t\t\t\targs: [stringToHex(validated.currency, { size: 32 })],\n\t\t\t}) as Promise<PriceConfig>,\n\t\t\t(error) =>\n\t\t\t\tnew ProfileError(\"Failed to read price config\", {\n\t\t\t\t\tcode: \"CONTRACT_READ_ERROR\",\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { currency: validated.currency, diamondAddress },\n\t\t\t\t}),\n\t\t),\n\t);\n}\n","import { SdkError } from \"../validation\";\n\nexport type ProfileErrorCode = \"VALIDATION_ERROR\" | \"CONTRACT_READ_ERROR\";\n\nexport class ProfileError extends SdkError<ProfileErrorCode> {\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\tcode: ProfileErrorCode;\n\t\t\tcause?: unknown;\n\t\t\tcontext?: Record<string, unknown>;\n\t\t},\n\t) {\n\t\tsuper(message, options);\n\t\tthis.name = \"ProfileError\";\n\t}\n}\n","import { z } from \"zod\";\nimport { ZodAddressSchema, ZodCurrencySchema } from \"../validation/schemas\";\n\nexport const ZodUsdcBalanceParamsSchema = z.object({\n\taddress: ZodAddressSchema,\n});\n\nexport type UsdcBalanceParams = z.infer<typeof ZodUsdcBalanceParamsSchema>;\n\nexport const ZodGetBalancesParamsSchema = z.object({\n\taddress: ZodAddressSchema,\n\tcurrency: ZodCurrencySchema,\n});\n\nexport type GetBalancesParams = z.infer<typeof ZodGetBalancesParamsSchema>;\n\nexport const ZodTxLimitsParamsSchema = z.object({\n\taddress: ZodAddressSchema,\n\tcurrency: ZodCurrencySchema,\n});\n\nexport type TxLimitsParams = z.infer<typeof ZodTxLimitsParamsSchema>;\n\nexport const ZodPriceConfigParamsSchema = z.object({\n\tcurrency: ZodCurrencySchema,\n});\n\nexport type PriceConfigParams = z.infer<typeof ZodPriceConfigParamsSchema>;\n","import { Result } from \"neverthrow\";\nimport { type Address, encodeFunctionData } from \"viem\";\nimport { validate } from \"../../validation\";\nimport { ZkkycError } from \"../../zkkyc/errors\";\nimport type {\n\tAnonAadharProofParams,\n\tSocialVerifyParams,\n\tZkPassportRegisterParams,\n} from \"../../zkkyc/validation\";\nimport {\n\tZodAnonAadharProofParamsSchema,\n\tZodSocialVerifyParamsSchema,\n\tZodZkPassportRegisterParamsSchema,\n} from \"../../zkkyc/validation\";\nimport { ABIS } from \"../abis\";\n\n/** Prepares a social verification transaction. */\nexport function prepareSocialVerify(\n\treputationManagerAddress: Address,\n\tparams: SocialVerifyParams,\n): Result<{ to: Address; data: `0x${string}` }, ZkkycError> {\n\treturn validate(\n\t\tZodSocialVerifyParamsSchema,\n\t\tparams,\n\t\t(message, cause, data) =>\n\t\t\tnew ZkkycError(message, { code: \"VALIDATION_ERROR\", cause, context: { params: data } }),\n\t).andThen((validated) =>\n\t\tResult.fromThrowable(\n\t\t\t() => ({\n\t\t\t\tto: reputationManagerAddress,\n\t\t\t\tdata: encodeFunctionData({\n\t\t\t\t\tabi: ABIS.EXTERNAL.REPUTATION_MANAGER,\n\t\t\t\t\tfunctionName: \"socialVerify\",\n\t\t\t\t\targs: [\n\t\t\t\t\t\tvalidated._socialName,\n\t\t\t\t\t\tvalidated.proofs.map((proof) => ({\n\t\t\t\t\t\t\t...proof,\n\t\t\t\t\t\t\tsignedClaim: {\n\t\t\t\t\t\t\t\t...proof.signedClaim,\n\t\t\t\t\t\t\t\tclaim: {\n\t\t\t\t\t\t\t\t\t...proof.signedClaim.claim,\n\t\t\t\t\t\t\t\t\tidentifier: proof.signedClaim.claim.identifier as `0x${string}`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsignatures: proof.signedClaim.signatures as readonly `0x${string}`[],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})),\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t}),\n\t\t\t(error) =>\n\t\t\t\tnew ZkkycError(\"Failed to encode socialVerify\", {\n\t\t\t\t\tcode: \"ENCODE_ERROR\",\n\t\t\t\t\tcause: error,\n\t\t\t\t}),\n\t\t)(),\n\t);\n}\n\n/** Prepares a submit anon Aadhaar proof transaction. */\nexport function prepareSubmitAnonAadharProof(\n\treputationManagerAddress: Address,\n\tparams: AnonAadharProofParams,\n): Result<{ to: Address; data: `0x${string}` }, ZkkycError> {\n\treturn validate(\n\t\tZodAnonAadharProofParamsSchema,\n\t\tparams,\n\t\t(message, cause, data) =>\n\t\t\tnew ZkkycError(message, { code: \"VALIDATION_ERROR\", cause, context: { params: data } }),\n\t).andThen((validated) =>\n\t\tResult.fromThrowable(\n\t\t\t() => ({\n\t\t\t\tto: reputationManagerAddress,\n\t\t\t\tdata: encodeFunctionData({\n\t\t\t\t\tabi: ABIS.EXTERNAL.REPUTATION_MANAGER,\n\t\t\t\t\tfunctionName: \"submitAnonAadharProof\",\n\t\t\t\t\targs: [\n\t\t\t\t\t\tvalidated.nullifierSeed,\n\t\t\t\t\t\tvalidated.nullifier,\n\t\t\t\t\t\tvalidated.timestamp,\n\t\t\t\t\t\tvalidated.signal,\n\t\t\t\t\t\tvalidated.revealArray,\n\t\t\t\t\t\tvalidated.packedGroth16Proof,\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t}),\n\t\t\t(error) =>\n\t\t\t\tnew ZkkycError(\"Failed to encode submitAnonAadharProof\", {\n\t\t\t\t\tcode: \"ENCODE_ERROR\",\n\t\t\t\t\tcause: error,\n\t\t\t\t}),\n\t\t)(),\n\t);\n}\n\n/** Prepares a zkPassport registration transaction. */\nexport function prepareZkPassportRegister(\n\treputationManagerAddress: Address,\n\tparams: ZkPassportRegisterParams,\n): Result<{ to: Address; data: `0x${string}` }, ZkkycError> {\n\treturn validate(\n\t\tZodZkPassportRegisterParamsSchema,\n\t\tparams,\n\t\t(message, cause, data) =>\n\t\t\tnew ZkkycError(message, { code: \"VALIDATION_ERROR\", cause, context: { params: data } }),\n\t).andThen((validated) =>\n\t\tResult.fromThrowable(\n\t\t\t() => {\n\t\t\t\tconst { proofVerificationData, serviceConfig, committedInputs, version } = validated.params;\n\n\t\t\t\tconst proofVerificationParams = {\n\t\t\t\t\tversion: version as `0x${string}`,\n\t\t\t\t\tproofVerificationData: {\n\t\t\t\t\t\tvkeyHash: proofVerificationData.vkeyHash as `0x${string}`,\n\t\t\t\t\t\tproof: proofVerificationData.proof as `0x${string}`,\n\t\t\t\t\t\tpublicInputs: proofVerificationData.publicInputs as `0x${string}`[],\n\t\t\t\t\t},\n\t\t\t\t\tcommittedInputs: committedInputs as `0x${string}`,\n\t\t\t\t\tserviceConfig: {\n\t\t\t\t\t\tvalidityPeriodInSeconds: BigInt(serviceConfig.validityPeriodInSeconds),\n\t\t\t\t\t\tdomain: serviceConfig.domain,\n\t\t\t\t\t\tscope: serviceConfig.scope,\n\t\t\t\t\t\tdevMode: serviceConfig.devMode,\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\treturn {\n\t\t\t\t\tto: reputationManagerAddress,\n\t\t\t\t\tdata: encodeFunctionData({\n\t\t\t\t\t\tabi: ABIS.EXTERNAL.REPUTATION_MANAGER,\n\t\t\t\t\t\tfunctionName: \"zkPassportRegister\",\n\t\t\t\t\t\targs: [proofVerificationParams, validated.isIDCard],\n\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t},\n\t\t\t(error) =>\n\t\t\t\tnew ZkkycError(\"Failed to encode zkPassportRegister\", {\n\t\t\t\t\tcode: \"ENCODE_ERROR\",\n\t\t\t\t\tcause: error,\n\t\t\t\t}),\n\t\t)(),\n\t);\n}\n","import { z } from \"zod\";\nimport { ZodAddressSchema } from \"../validation\";\n\n// ── Write param schemas ──────────────────────────────────────────────────────\n\nexport const ZodAnonAadharProofParamsSchema = z.object({\n\tnullifierSeed: z.bigint(),\n\tnullifier: z.bigint(),\n\ttimestamp: z.bigint(),\n\tsignal: z.bigint(),\n\trevealArray: z.tuple([z.bigint(), z.bigint(), z.bigint(), z.bigint()]),\n\tpackedGroth16Proof: z.tuple([\n\t\tz.bigint(),\n\t\tz.bigint(),\n\t\tz.bigint(),\n\t\tz.bigint(),\n\t\tz.bigint(),\n\t\tz.bigint(),\n\t\tz.bigint(),\n\t\tz.bigint(),\n\t]),\n});\n\nexport type AnonAadharProofParams = z.infer<typeof ZodAnonAadharProofParamsSchema>;\n\nexport const ZodSocialVerifyParamsSchema = z.object({\n\t_socialName: z.string(),\n\tproofs: z.array(\n\t\tz.object({\n\t\t\tclaimInfo: z.object({\n\t\t\t\tprovider: z.string(),\n\t\t\t\tparameters: z.string(),\n\t\t\t\tcontext: z.string(),\n\t\t\t}),\n\t\t\tsignedClaim: z.object({\n\t\t\t\tclaim: z.object({\n\t\t\t\t\tidentifier: z.string(),\n\t\t\t\t\towner: ZodAddressSchema,\n\t\t\t\t\ttimestampS: z.number(),\n\t\t\t\t\tepoch: z.number(),\n\t\t\t\t}),\n\t\t\t\tsignatures: z.array(z.string()),\n\t\t\t}),\n\t\t}),\n\t),\n});\n\nexport type SocialVerifyParams = z.infer<typeof ZodSocialVerifyParamsSchema>;\n\n// Schema matching SolidityVerifierParameters from @zkpassport/sdk (structural definition)\nexport const ZodSolidityVerifierParametersSchema = z.object({\n\tversion: z.string().refine((val) => val.startsWith(\"0x\"), {\n\t\tmessage: \"Version must be a hex string\",\n\t}),\n\tproofVerificationData: z.object({\n\t\tvkeyHash: z.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {\n\t\t\tmessage: \"Invalid bytes32 hex string\",\n\t\t}),\n\t\tproof: z.string().refine((val) => val.startsWith(\"0x\"), {\n\t\t\tmessage: \"Proof must be a hex string\",\n\t\t}),\n\t\tpublicInputs: z.array(\n\t\t\tz.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {\n\t\t\t\tmessage: \"Each public input must be a valid bytes32 hex string\",\n\t\t\t}),\n\t\t),\n\t}),\n\tcommittedInputs: z.string().refine((val) => val.startsWith(\"0x\"), {\n\t\tmessage: \"Committed inputs must be a hex string\",\n\t}),\n\tserviceConfig: z.object({\n\t\tvalidityPeriodInSeconds: z.number().int().nonnegative(),\n\t\tdomain: z.string(),\n\t\tscope: z.string(),\n\t\tdevMode: z.boolean(),\n\t}),\n});\n\nexport type SolidityVerifierParameters = z.infer<typeof ZodSolidityVerifierParametersSchema>;\n\nexport const ZodZkPassportRegisterParamsSchema = z.object({\n\tparams: ZodSolidityVerifierParametersSchema,\n\tisIDCard: z.boolean(),\n});\n\nexport type ZkPassportRegisterParams = z.infer<typeof ZodZkPassportRegisterParamsSchema>;\n","import { ResultAsync } from \"neverthrow\";\nimport { type Address, formatUnits, stringToHex } from \"viem\";\nimport { ProfileError } from \"../../profile/errors\";\nimport type { PriceConfigParams, TxLimitsParams } from \"../../profile/validation\";\nimport { ZodPriceConfigParamsSchema, ZodTxLimitsParamsSchema } from \"../../profile/validation\";\nimport type { PublicClientLike } from \"../../types\";\nimport { validate } from \"../../validation\";\nimport { ABIS } from \"../abis\";\n\nexport interface TxLimits {\n\treadonly buyLimit: number;\n\treadonly sellLimit: number;\n}\n\nexport interface RpPerUsdtLimit {\n\treadonly numerator: bigint;\n\treadonly denominator: bigint;\n\t/** The USDC multiplier per RP: denominator / numerator. */\n\treadonly multiplier: number;\n}\n\n/** Reads the buy and sell transaction limits for a given address and currency. */\nexport function getTxLimits(\n\tpublicClient: PublicClientLike,\n\tdiamondAddress: Address,\n\tparams: TxLimitsParams,\n): ResultAsync<TxLimits, ProfileError> {\n\treturn validate(\n\t\tZodTxLimitsParamsSchema,\n\t\tparams,\n\t\t(message, cause, data) =>\n\t\t\tnew ProfileError(message, {\n\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\tcause,\n\t\t\t\tcontext: { params: data },\n\t\t\t}),\n\t).asyncAndThen((validated) =>\n\t\tResultAsync.fromPromise(\n\t\t\tpublicClient.readContract({\n\t\t\t\taddress: diamondAddress,\n\t\t\t\tabi: ABIS.FACETS.ORDER_FLOW,\n\t\t\t\tfunctionName: \"userTxLimit\",\n\t\t\t\targs: [validated.address, stringToHex(validated.currency, { size: 32 })],\n\t\t\t}) as Promise<readonly [bigint, bigint]>,\n\t\t\t(error) =>\n\t\t\t\tnew ProfileError(\"Failed to read tx limits\", {\n\t\t\t\t\tcode: \"CONTRACT_READ_ERROR\",\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { address: validated.address, currency: validated.currency, diamondAddress },\n\t\t\t\t}),\n\t\t).map(([buyLimit, sellLimit]) => ({\n\t\t\tbuyLimit: Number(formatUnits(buyLimit, 6)),\n\t\t\tsellLimit: Number(formatUnits(sellLimit, 6)),\n\t\t})),\n\t);\n}\n/** Reads the RP-to-USDC limit ratio for a given currency from the Diamond contract. */\nexport function getRpPerUsdtLimitRational(\n\tpublicClient: PublicClientLike,\n\tdiamondAddress: Address,\n\tparams: PriceConfigParams,\n): ResultAsync<RpPerUsdtLimit, ProfileError> {\n\treturn validate(\n\t\tZodPriceConfigParamsSchema,\n\t\tparams,\n\t\t(message, cause, data) =>\n\t\t\tnew ProfileError(message, {\n\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\tcause,\n\t\t\t\tcontext: { params: data },\n\t\t\t}),\n\t).asyncAndThen((validated) =>\n\t\tResultAsync.fromPromise(\n\t\t\tpublicClient.readContract({\n\t\t\t\taddress: diamondAddress,\n\t\t\t\tabi: ABIS.DIAMOND,\n\t\t\t\tfunctionName: \"getRpPerUsdtLimitRational\",\n\t\t\t\targs: [stringToHex(validated.currency, { size: 32 })],\n\t\t\t}) as Promise<readonly [bigint, bigint]>,\n\t\t\t(error) =>\n\t\t\t\tnew ProfileError(\"Failed to read RP per USDT limit rational\", {\n\t\t\t\t\tcode: \"CONTRACT_READ_ERROR\",\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { currency: validated.currency, diamondAddress },\n\t\t\t\t}),\n\t\t).map(([numerator, denominator]) => ({\n\t\t\tnumerator,\n\t\t\tdenominator,\n\t\t\tmultiplier: numerator > 0n ? Number(denominator) / Number(numerator) : 0,\n\t\t})),\n\t);\n}\n","import { ResultAsync } from \"neverthrow\";\nimport type { Address } from \"viem\";\nimport { ProfileError } from \"../../profile/errors\";\nimport type { UsdcBalanceParams } from \"../../profile/validation\";\nimport { ZodUsdcBalanceParamsSchema } from \"../../profile/validation\";\nimport type { PublicClientLike } from \"../../types\";\nimport { validate } from \"../../validation\";\nimport { ABIS } from \"../abis\";\n\n/** Reads the USDC balance for a given address. */\nexport function getUsdcBalance(\n\tpublicClient: PublicClientLike,\n\tusdcAddress: Address,\n\tparams: UsdcBalanceParams,\n): ResultAsync<bigint, ProfileError> {\n\treturn validate(\n\t\tZodUsdcBalanceParamsSchema,\n\t\tparams,\n\t\t(message, cause, data) =>\n\t\t\tnew ProfileError(message, {\n\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\tcause,\n\t\t\t\tcontext: { params: data },\n\t\t\t}),\n\t).asyncAndThen((validated) =>\n\t\tResultAsync.fromPromise(\n\t\t\tpublicClient.readContract({\n\t\t\t\taddress: usdcAddress,\n\t\t\t\tabi: ABIS.EXTERNAL.USDC,\n\t\t\t\tfunctionName: \"balanceOf\",\n\t\t\t\targs: [validated.address],\n\t\t\t}) as Promise<bigint>,\n\t\t\t(error) =>\n\t\t\t\tnew ProfileError(\"Failed to read USDC balance\", {\n\t\t\t\t\tcode: \"CONTRACT_READ_ERROR\",\n\t\t\t\t\tcause: error,\n\t\t\t\t\tcontext: { address: validated.address, usdcAddress },\n\t\t\t\t}),\n\t\t),\n\t);\n}\n","import { ResultAsync } from \"neverthrow\";\nimport { type Address, formatUnits } from \"viem\";\nimport { getPriceConfig, getUsdcBalance } from \"../../contracts\";\nimport { validate } from \"../../validation\";\nimport { ProfileError } from \"../errors\";\nimport type { Balances, GetBalancesParams, PublicClientLike } from \"../types\";\nimport { ZodGetBalancesParamsSchema } from \"../validation\";\n\n/** Fetches USDC balance and fiat equivalent in parallel for a given address and currency. */\nexport function getBalances(\n\tpublicClient: PublicClientLike,\n\tusdcAddress: Address,\n\tdiamondAddress: Address,\n\tparams: GetBalancesParams,\n): ResultAsync<Balances, ProfileError> {\n\treturn validate(\n\t\tZodGetBalancesParamsSchema,\n\t\tparams,\n\t\t(message, cause, data) =>\n\t\t\tnew ProfileError(message, {\n\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\tcause,\n\t\t\t\tcontext: { params: data },\n\t\t\t}),\n\t).asyncAndThen((validated) =>\n\t\tResultAsync.combine([\n\t\t\tgetUsdcBalance(publicClient, usdcAddress, {\n\t\t\t\taddress: validated.address,\n\t\t\t}),\n\t\t\tgetPriceConfig(publicClient, diamondAddress, {\n\t\t\t\tcurrency: validated.currency,\n\t\t\t}),\n\t\t]).map(([usdc, priceConfig]) => {\n\t\t\tconst usdcFormatted = Number(formatUnits(usdc, 6));\n\t\t\tconst sellPriceFormatted = Number(formatUnits(priceConfig.sellPrice, 6));\n\t\t\treturn {\n\t\t\t\tusdc: usdcFormatted,\n\t\t\t\tfiat: usdcFormatted * sellPriceFormatted,\n\t\t\t\tsellPrice: sellPriceFormatted,\n\t\t\t};\n\t\t}),\n\t);\n}\n","import type { ResultAsync } from \"neverthrow\";\nimport {\n\tgetPriceConfig,\n\tgetRpPerUsdtLimitRational,\n\tgetTxLimits,\n\tgetUsdcBalance,\n} from \"../contracts\";\nimport type { RpPerUsdtLimit, TxLimits } from \"../contracts/tx-limits\";\nimport { getBalances } from \"./contracts\";\nimport type { ProfileError } from \"./errors\";\nimport type {\n\tBalances,\n\tGetBalancesParams,\n\tPriceConfig,\n\tPriceConfigParams,\n\tProfileConfig,\n\tTxLimitsParams,\n\tUsdcBalanceParams,\n} from \"./types\";\n\nexport interface Profile {\n\t/** Reads the USDC balance for a given address (raw bigint, 6 decimals). */\n\tgetUsdcBalance(params: UsdcBalanceParams): ResultAsync<bigint, ProfileError>;\n\n\t/** Reads buy/sell price config for a given currency (raw bigint, 6 decimals). */\n\tgetPriceConfig(params: PriceConfigParams): ResultAsync<PriceConfig, ProfileError>;\n\n\t/** Fetches USDC and fiat balance in parallel for a given address and currency. */\n\tgetBalances(params: GetBalancesParams): ResultAsync<Balances, ProfileError>;\n\n\t/** Reads buy and sell transaction limits for a given address and currency. */\n\tgetTxLimits(params: TxLimitsParams): ResultAsync<TxLimits, ProfileError>;\n\n\t/** Reads the RP-to-USDC limit ratio for a given currency. */\n\tgetRpPerUsdtLimitRational(params: PriceConfigParams): ResultAsync<RpPerUsdtLimit, ProfileError>;\n}\n\n/** Creates a Profile SDK instance for reading account balance and price data. */\nexport function createProfile(config: ProfileConfig): Profile {\n\tconst { publicClient, diamondAddress, usdcAddress } = config;\n\n\treturn {\n\t\tgetUsdcBalance: (params: UsdcBalanceParams) =>\n\t\t\tgetUsdcBalance(publicClient, usdcAddress, params),\n\n\t\tgetPriceConfig: (params: PriceConfigParams) =>\n\t\t\tgetPriceConfig(publicClient, diamondAddress, params),\n\n\t\tgetBalances: (params: GetBalancesParams) =>\n\t\t\tgetBalances(publicClient, usdcAddress, diamondAddress, params),\n\n\t\tgetTxLimits: (params: TxLimitsParams) => getTxLimits(publicClient, diamondAddress, params),\n\n\t\tgetRpPerUsdtLimitRational: (params: PriceConfigParams) =>\n\t\t\tgetRpPerUsdtLimitRational(publicClient, diamondAddress, params),\n\t};\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAlB,IAAM,oBAAoB;AAAA,EAChC;AAAA,IACC,QAAQ;AAAA,MACP,EAAE,cAAc,WAAW,MAAM,YAAY,MAAM,UAAU;AAAA,MAC7D,EAAE,cAAc,WAAW,MAAM,cAAc,MAAM,UAAU;AAAA,MAC/D,EAAE,cAAc,WAAW,MAAM,YAAY,MAAM,UAAU;AAAA,MAC7D,EAAE,cAAc,WAAW,MAAM,QAAQ,MAAM,UAAU;AAAA,MACzD,EAAE,cAAc,WAAW,MAAM,cAAc,MAAM,UAAU;AAAA,MAC/D,EAAE,cAAc,WAAW,MAAM,cAAc,MAAM,UAAU;AAAA,MAC/D,EAAE,cAAc,UAAU,MAAM,aAAa,MAAM,SAAS;AAAA,MAC5D,EAAE,cAAc,WAAW,MAAM,uBAAuB,MAAM,UAAU;AAAA,IACzE;AAAA,IACA,MAAM;AAAA,IACN,SAAS,CAAC,EAAE,cAAc,aAAa,MAAM,IAAI,MAAM,YAAY,CAAC;AAAA,IACpE,iBAAiB;AAAA,IACjB,MAAM;AAAA,EACP;AAAA,EACA;AAAA,IACC,QAAQ;AAAA,MACP,EAAE,cAAc,WAAW,MAAM,SAAS,MAAM,UAAU;AAAA,MAC1D,EAAE,cAAc,WAAW,MAAM,mBAAmB,MAAM,UAAU;AAAA,IACrE;AAAA,IACA,MAAM;AAAA,IACN,SAAS;AAAA,MACR,EAAE,cAAc,WAAW,MAAM,IAAI,MAAM,UAAU;AAAA,MACrD,EAAE,cAAc,WAAW,MAAM,IAAI,MAAM,UAAU;AAAA,IACtD;AAAA,IACA,iBAAiB;AAAA,IACjB,MAAM;AAAA,EACP;AACD;;;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D,aAAa,CAAC,WACb,YAAY,cAAc,aAAa,gBAAgB,MAAM;AAAA,IAE9D,aAAa,CAAC,WAA2B,YAAY,cAAc,gBAAgB,MAAM;AAAA,IAEzF,2BAA2B,CAAC,WAC3B,0BAA0B,cAAc,gBAAgB,MAAM;AAAA,EAChE;AACD;","names":["z","z","ResultAsync","z","z","ResultAsync","z","z","ResultAsync","stringToHex","ResultAsync","stringToHex","ResultAsync","ResultAsync","ResultAsync","formatUnits","ResultAsync","formatUnits"]}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/qr-parsers/index.ts
|
|
21
|
+
var qr_parsers_exports = {};
|
|
22
|
+
__export(qr_parsers_exports, {
|
|
23
|
+
QRParserError: () => QRParserError,
|
|
24
|
+
parseQR: () => parseQR
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(qr_parsers_exports);
|
|
27
|
+
|
|
28
|
+
// src/qr-parsers/errors.ts
|
|
29
|
+
var QRParserError = class extends Error {
|
|
30
|
+
code;
|
|
31
|
+
cause;
|
|
32
|
+
context;
|
|
33
|
+
constructor(message, options) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = "QRParserError";
|
|
36
|
+
this.code = options.code;
|
|
37
|
+
this.cause = options.cause;
|
|
38
|
+
this.context = options.context;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/qr-parsers/types.ts
|
|
43
|
+
var import_neverthrow = require("neverthrow");
|
|
44
|
+
function success(data) {
|
|
45
|
+
return (0, import_neverthrow.ok)(data);
|
|
46
|
+
}
|
|
47
|
+
function failure(code, message, context) {
|
|
48
|
+
return (0, import_neverthrow.err)(new QRParserError(message, { code, context }));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/qr-parsers/utils/crc16.ts
|
|
52
|
+
function calculateCRC16(data) {
|
|
53
|
+
const payload = `${data}6304`;
|
|
54
|
+
const polynomial = 4129;
|
|
55
|
+
let result = 65535;
|
|
56
|
+
const encoder = new TextEncoder();
|
|
57
|
+
const bytes = encoder.encode(payload);
|
|
58
|
+
for (let offset = 0; offset < bytes.length; offset++) {
|
|
59
|
+
result ^= bytes[offset] << 8;
|
|
60
|
+
for (let bitwise = 0; bitwise < 8; bitwise++) {
|
|
61
|
+
result <<= 1;
|
|
62
|
+
if (result & 65536) {
|
|
63
|
+
result ^= polynomial;
|
|
64
|
+
}
|
|
65
|
+
result &= 65535;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return result.toString(16).toUpperCase().padStart(4, "0");
|
|
69
|
+
}
|
|
70
|
+
function verifyCRC16(qrData) {
|
|
71
|
+
if (!qrData || qrData.length < 8) {
|
|
72
|
+
return { valid: false, error: "QR data too short for CRC verification" };
|
|
73
|
+
}
|
|
74
|
+
const crcTagIndex = qrData.lastIndexOf("6304");
|
|
75
|
+
if (crcTagIndex === -1 || crcTagIndex + 8 !== qrData.length) {
|
|
76
|
+
return { valid: false, error: "Missing or misplaced CRC tag (6304)" };
|
|
77
|
+
}
|
|
78
|
+
const providedCrc = qrData.substring(crcTagIndex + 4, crcTagIndex + 8);
|
|
79
|
+
if (!/^[0-9A-Fa-f]{4}$/.test(providedCrc)) {
|
|
80
|
+
return { valid: false, error: "Invalid CRC hex format" };
|
|
81
|
+
}
|
|
82
|
+
const dataBeforeCrc = qrData.substring(0, crcTagIndex);
|
|
83
|
+
const calculatedCrc = calculateCRC16(dataBeforeCrc);
|
|
84
|
+
if (calculatedCrc !== providedCrc.toUpperCase()) {
|
|
85
|
+
return {
|
|
86
|
+
valid: false,
|
|
87
|
+
error: `CRC mismatch: expected ${calculatedCrc}, got ${providedCrc.toUpperCase()}`
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return { valid: true };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/qr-parsers/utils/tlv.ts
|
|
94
|
+
function parseTLV(data) {
|
|
95
|
+
const entries = [];
|
|
96
|
+
let pos = 0;
|
|
97
|
+
while (pos + 4 <= data.length) {
|
|
98
|
+
const tag = data.substring(pos, pos + 2);
|
|
99
|
+
const lengthStr = data.substring(pos + 2, pos + 4);
|
|
100
|
+
if (!/^[0-9]{2}$/.test(tag) || !/^[0-9]{2}$/.test(lengthStr)) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const length = parseInt(lengthStr, 10);
|
|
104
|
+
if (pos + 4 + length > data.length) {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
const value = data.substring(pos + 4, pos + 4 + length);
|
|
108
|
+
entries.push({ tag, value });
|
|
109
|
+
pos += 4 + length;
|
|
110
|
+
}
|
|
111
|
+
return entries;
|
|
112
|
+
}
|
|
113
|
+
function extractTags(data, tags) {
|
|
114
|
+
const result = {};
|
|
115
|
+
const tagSet = new Set(tags);
|
|
116
|
+
for (const entry of parseTLV(data)) {
|
|
117
|
+
if (tagSet.has(entry.tag)) {
|
|
118
|
+
result[entry.tag] = entry.value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/qr-parsers/parsers/ars.ts
|
|
125
|
+
function parseMercadoPago(qrData, _sellPrice) {
|
|
126
|
+
if (!qrData || typeof qrData !== "string" || qrData.trim().length === 0) {
|
|
127
|
+
return failure("INVALID_QR", "QR data is empty or invalid");
|
|
128
|
+
}
|
|
129
|
+
const trimmed = qrData.trim();
|
|
130
|
+
const isARS = trimmed.includes("5303032");
|
|
131
|
+
const isAR = trimmed.includes("5802AR");
|
|
132
|
+
if (!isARS && !isAR) {
|
|
133
|
+
return failure("INVALID_QR", "Not an ARS/Argentina QR code");
|
|
134
|
+
}
|
|
135
|
+
const crc = verifyCRC16(trimmed);
|
|
136
|
+
if (!crc.valid) {
|
|
137
|
+
return failure("INVALID_QR", "Invalid QR checksum");
|
|
138
|
+
}
|
|
139
|
+
const tags = extractTags(trimmed, ["59"]);
|
|
140
|
+
const merchantName = tags["59"] || "Unknown";
|
|
141
|
+
return success({ paymentAddress: merchantName });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/qr-parsers/parsers/brl.ts
|
|
145
|
+
var import_neverthrow2 = require("neverthrow");
|
|
146
|
+
|
|
147
|
+
// src/qr-parsers/utils/amount.ts
|
|
148
|
+
function parseAmount(amountStr, sellPrice) {
|
|
149
|
+
if (!amountStr || amountStr.trim() === "") return null;
|
|
150
|
+
const fiat = parseFloat(amountStr.trim());
|
|
151
|
+
if (Number.isNaN(fiat) || fiat <= 0) return null;
|
|
152
|
+
return { usdc: fiat / sellPrice, fiat };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/qr-parsers/parsers/brl.ts
|
|
156
|
+
var PIX_TAGS = {
|
|
157
|
+
PAYLOAD_FORMAT: "00",
|
|
158
|
+
PIX_KEY_INFO: "26",
|
|
159
|
+
AMOUNT: "54",
|
|
160
|
+
MERCHANT_NAME: "59",
|
|
161
|
+
CRC: "63"
|
|
162
|
+
};
|
|
163
|
+
function parsePIXKeyInfo(data) {
|
|
164
|
+
const result = { pixKey: null, location: null };
|
|
165
|
+
for (const entry of parseTLV(data)) {
|
|
166
|
+
if (entry.tag === "01") {
|
|
167
|
+
if (entry.value.includes("http") || entry.value.includes("://")) {
|
|
168
|
+
result.location = entry.value.startsWith("http") ? entry.value : `https://${entry.value}`;
|
|
169
|
+
} else {
|
|
170
|
+
result.pixKey = entry.value;
|
|
171
|
+
}
|
|
172
|
+
} else if (entry.tag === "25") {
|
|
173
|
+
result.location = entry.value.startsWith("http") ? entry.value : `https://${entry.value}`;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
function safeBase64Decode(base64String) {
|
|
179
|
+
if (typeof globalThis.atob === "function") {
|
|
180
|
+
return globalThis.atob(base64String);
|
|
181
|
+
}
|
|
182
|
+
throw new Error("No base64 decoder available");
|
|
183
|
+
}
|
|
184
|
+
function parseJWT(token) {
|
|
185
|
+
try {
|
|
186
|
+
const parts = token.trim().split(".");
|
|
187
|
+
if (parts.length !== 3 || !parts[0] || !parts[1] || !parts[2]) return null;
|
|
188
|
+
const json = safeBase64Decode(parts[1]);
|
|
189
|
+
return JSON.parse(json);
|
|
190
|
+
} catch {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function dynamicErr(code, message) {
|
|
195
|
+
return (0, import_neverthrow2.err)(new QRParserError(message, { code }));
|
|
196
|
+
}
|
|
197
|
+
async function fetchDynamicData(location, proxyUrl, orderId) {
|
|
198
|
+
try {
|
|
199
|
+
const url = new URL(`${proxyUrl}/pix`);
|
|
200
|
+
url.searchParams.set("locationUrl", location);
|
|
201
|
+
if (orderId) {
|
|
202
|
+
url.searchParams.set("orderId", orderId);
|
|
203
|
+
}
|
|
204
|
+
const response = await fetch(url, {
|
|
205
|
+
method: "GET",
|
|
206
|
+
headers: { Accept: "*/*" }
|
|
207
|
+
});
|
|
208
|
+
if (!response.ok) {
|
|
209
|
+
return dynamicErr("FETCH_FAILED", `Proxy error: ${response.status} ${response.statusText}`);
|
|
210
|
+
}
|
|
211
|
+
const jwtToken = await response.text();
|
|
212
|
+
const payload = parseJWT(jwtToken);
|
|
213
|
+
if (!payload) {
|
|
214
|
+
return dynamicErr("FETCH_FAILED", "Failed to parse dynamic PIX response");
|
|
215
|
+
}
|
|
216
|
+
return (0, import_neverthrow2.ok)({ dynamicAmount: payload.valor?.original });
|
|
217
|
+
} catch (error) {
|
|
218
|
+
const msg = error instanceof Error ? error.message : "Unknown error";
|
|
219
|
+
return dynamicErr("FETCH_FAILED", `Failed to fetch dynamic PIX data: ${msg}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async function parsePIX(qrData, sellPrice, config) {
|
|
223
|
+
if (!qrData || typeof qrData !== "string" || qrData.trim().length === 0) {
|
|
224
|
+
return failure("INVALID_QR", "QR data is empty or invalid");
|
|
225
|
+
}
|
|
226
|
+
const trimmed = qrData.trim();
|
|
227
|
+
const crc = verifyCRC16(trimmed);
|
|
228
|
+
if (!crc.valid) {
|
|
229
|
+
return failure("INVALID_QR", "Invalid QR checksum");
|
|
230
|
+
}
|
|
231
|
+
const allTags = {};
|
|
232
|
+
for (const entry of parseTLV(trimmed)) {
|
|
233
|
+
allTags[entry.tag] = entry.value;
|
|
234
|
+
}
|
|
235
|
+
if (!allTags[PIX_TAGS.PAYLOAD_FORMAT]) {
|
|
236
|
+
return failure("INVALID_QR", "Invalid PIX QR format");
|
|
237
|
+
}
|
|
238
|
+
const merchantName = allTags[PIX_TAGS.MERCHANT_NAME] || "MERCHANT_NOT_FOUND";
|
|
239
|
+
let dynamicAmount;
|
|
240
|
+
const pixKeyData = allTags[PIX_TAGS.PIX_KEY_INFO];
|
|
241
|
+
if (pixKeyData) {
|
|
242
|
+
const { location } = parsePIXKeyInfo(pixKeyData);
|
|
243
|
+
if (location) {
|
|
244
|
+
if (!config.proxyUrl) {
|
|
245
|
+
return failure("FETCH_FAILED", "proxyUrl is required for dynamic PIX QR codes");
|
|
246
|
+
}
|
|
247
|
+
const dynamicResult = await fetchDynamicData(location, config.proxyUrl, config.orderId);
|
|
248
|
+
if (dynamicResult.isErr()) {
|
|
249
|
+
return (0, import_neverthrow2.err)(dynamicResult.error);
|
|
250
|
+
}
|
|
251
|
+
dynamicAmount = dynamicResult.value.dynamicAmount;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const fiatAmountStr = dynamicAmount || allTags[PIX_TAGS.AMOUNT];
|
|
255
|
+
const result = { paymentAddress: merchantName };
|
|
256
|
+
if (fiatAmountStr) {
|
|
257
|
+
const amount = parseAmount(fiatAmountStr, sellPrice);
|
|
258
|
+
if (amount) {
|
|
259
|
+
result.amount = amount;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return success(result);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// src/qr-parsers/parsers/idr.ts
|
|
266
|
+
var QRIS_TAGS = { AMOUNT: "54", MERCHANT_NAME: "59" };
|
|
267
|
+
function parseQRIS(qrData, sellPrice) {
|
|
268
|
+
if (!qrData || typeof qrData !== "string" || qrData.trim().length === 0) {
|
|
269
|
+
return failure("INVALID_QR", "QR data is empty or invalid");
|
|
270
|
+
}
|
|
271
|
+
const trimmed = qrData.trim();
|
|
272
|
+
const tags = extractTags(trimmed, [QRIS_TAGS.AMOUNT, QRIS_TAGS.MERCHANT_NAME]);
|
|
273
|
+
const merchantName = tags[QRIS_TAGS.MERCHANT_NAME];
|
|
274
|
+
if (!merchantName) {
|
|
275
|
+
return failure("INVALID_QR", "Missing merchant name");
|
|
276
|
+
}
|
|
277
|
+
const result = { paymentAddress: merchantName };
|
|
278
|
+
const amountStr = tags[QRIS_TAGS.AMOUNT];
|
|
279
|
+
if (amountStr) {
|
|
280
|
+
const amount = parseAmount(amountStr, sellPrice);
|
|
281
|
+
if (!amount) {
|
|
282
|
+
return failure("INVALID_AMOUNT", "Invalid amount in QR");
|
|
283
|
+
}
|
|
284
|
+
result.amount = amount;
|
|
285
|
+
}
|
|
286
|
+
return success(result);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/qr-parsers/parsers/inr.ts
|
|
290
|
+
var UPI_ID_REGEX = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+$/;
|
|
291
|
+
function parseUPI(qrData, sellPrice) {
|
|
292
|
+
if (!qrData || typeof qrData !== "string" || qrData.trim().length === 0) {
|
|
293
|
+
return failure("INVALID_QR", "QR data is empty or invalid");
|
|
294
|
+
}
|
|
295
|
+
const trimmed = qrData.trim();
|
|
296
|
+
let paramString;
|
|
297
|
+
if (trimmed.startsWith("upi://pay?")) {
|
|
298
|
+
paramString = trimmed.substring(10);
|
|
299
|
+
} else if (trimmed.includes("?")) {
|
|
300
|
+
paramString = trimmed.split("?")[1];
|
|
301
|
+
} else {
|
|
302
|
+
paramString = trimmed;
|
|
303
|
+
}
|
|
304
|
+
const params = new URLSearchParams(paramString);
|
|
305
|
+
const pa = params.get("pa");
|
|
306
|
+
if (!pa) {
|
|
307
|
+
return failure("INVALID_QR", "Missing UPI payment address");
|
|
308
|
+
}
|
|
309
|
+
if (!UPI_ID_REGEX.test(pa)) {
|
|
310
|
+
return failure("INVALID_QR", "Invalid UPI ID format");
|
|
311
|
+
}
|
|
312
|
+
const result = { paymentAddress: pa };
|
|
313
|
+
const amountStr = params.get("am");
|
|
314
|
+
if (amountStr) {
|
|
315
|
+
const amount = parseAmount(amountStr, sellPrice);
|
|
316
|
+
if (!amount) {
|
|
317
|
+
return failure("INVALID_AMOUNT", "Invalid amount in QR");
|
|
318
|
+
}
|
|
319
|
+
result.amount = amount;
|
|
320
|
+
}
|
|
321
|
+
return success(result);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// src/qr-parsers/parsers/ven.ts
|
|
325
|
+
function parsePagoMovil(qrData, _sellPrice) {
|
|
326
|
+
if (!qrData || typeof qrData !== "string" || qrData.trim().length === 0) {
|
|
327
|
+
return failure("INVALID_QR", "QR data is empty or invalid");
|
|
328
|
+
}
|
|
329
|
+
const trimmed = qrData.trim();
|
|
330
|
+
const qIdx = trimmed.indexOf("?");
|
|
331
|
+
if (qIdx === -1) {
|
|
332
|
+
return failure("INVALID_QR", "Not a valid Venezuelan QR code");
|
|
333
|
+
}
|
|
334
|
+
const payload = trimmed.substring(0, qIdx);
|
|
335
|
+
if (!payload || !/^[A-Za-z0-9+/=]+$/.test(payload)) {
|
|
336
|
+
return failure("INVALID_QR", "Not a valid Venezuelan QR code");
|
|
337
|
+
}
|
|
338
|
+
return success({ paymentAddress: trimmed });
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/qr-parsers/parse-qr.ts
|
|
342
|
+
async function parseQR(qrData, currency, sellPrice, config) {
|
|
343
|
+
if (!qrData || typeof qrData !== "string" || qrData.trim().length === 0) {
|
|
344
|
+
return failure("INVALID_QR", "QR data is empty or invalid");
|
|
345
|
+
}
|
|
346
|
+
switch (currency) {
|
|
347
|
+
case "INR":
|
|
348
|
+
return parseUPI(qrData, sellPrice);
|
|
349
|
+
case "IDR":
|
|
350
|
+
return parseQRIS(qrData, sellPrice);
|
|
351
|
+
case "BRL":
|
|
352
|
+
return parsePIX(qrData, sellPrice, config ?? {});
|
|
353
|
+
case "ARS":
|
|
354
|
+
return parseMercadoPago(qrData, sellPrice);
|
|
355
|
+
case "VEN":
|
|
356
|
+
return parsePagoMovil(qrData, sellPrice);
|
|
357
|
+
default:
|
|
358
|
+
return failure("INVALID_CURRENCY", `Currency "${currency}" is not supported`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
362
|
+
0 && (module.exports = {
|
|
363
|
+
QRParserError,
|
|
364
|
+
parseQR
|
|
365
|
+
});
|
|
366
|
+
//# sourceMappingURL=qr-parsers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/qr-parsers/index.ts","../src/qr-parsers/errors.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\tParseQRConfig,\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","import { err, ok, type Result } from \"neverthrow\";\nimport { QRParserError, type QRParserErrorCode } from \"./errors\";\n\nexport type SupportedCurrency = \"INR\" | \"IDR\" | \"BRL\" | \"ARS\" | \"VEN\";\n\nexport interface ParseQRConfig {\n\tproxyUrl?: string;\n\torderId?: 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 { 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 { ParseQRConfig, ParseResult, SupportedCurrency } 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 `pix-proxy` / `config.proxyUrl`),\n * which returns a signed JWT whose `valor.original` field holds the amount.\n * All other parsers (UPI, QRIS, MercadoPago, PagoMovil) and static PIX are\n * synchronous and resolve immediately.\n */\nexport async function parseQR(\n\tqrData: string,\n\tcurrency: SupportedCurrency,\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\tswitch (currency) {\n\t\tcase \"INR\":\n\t\t\treturn parseUPI(qrData, sellPrice);\n\t\tcase \"IDR\":\n\t\t\treturn parseQRIS(qrData, sellPrice);\n\t\tcase \"BRL\":\n\t\t\treturn parsePIX(qrData, sellPrice, config ?? {});\n\t\tcase \"ARS\":\n\t\t\treturn parseMercadoPago(qrData, sellPrice);\n\t\tcase \"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;;;ACzBA,wBAAqC;AAoB9B,SAAS,QAAQ,MAA6B;AACpD,aAAO,sBAAG,IAAI;AACf;AAEO,SAAS,QACf,MACA,SACA,SACc;AACd,aAAO,uBAAI,IAAI,cAAc,SAAS,EAAE,MAAM,QAAQ,CAAC,CAAC;AACzD;;;ACzBO,SAAS,eAAe,MAAsB;AACpD,QAAM,UAAU,GAAG,IAAI;AACvB,QAAM,aAAa;AACnB,MAAI,SAAS;AAEb,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,Q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I,CAAC,UAAU,OAAO,WAAW,YAAY,OAAO,KAAK,EAAE,WAAW,GAAG;AACxE,WAAO,QAAQ,cAAc,6BAA6B;AAAA,EAC3D;AAEA,QAAM,UAAU,OAAO,KAAK;AAE5B,QAAM,OAAO,QAAQ,QAAQ,GAAG;AAChC,MAAI,SAAS,IAAI;AAChB,WAAO,QAAQ,cAAc,gCAAgC;AAAA,EAC9D;AAEA,QAAM,UAAU,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;;;ACJA,eAAsB,QACrB,QACA,UACA,WACA,QACuB;AACvB,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,OAAO,KAAK,EAAE,WAAW,GAAG;AACxE,WAAO,QAAQ,cAAc,6BAA6B;AAAA,EAC3D;AAEA,UAAQ,UAAU;AAAA,IACjB,KAAK;AACJ,aAAO,SAAS,QAAQ,SAAS;AAAA,IAClC,KAAK;AACJ,aAAO,UAAU,QAAQ,SAAS;AAAA,IACnC,KAAK;AACJ,aAAO,SAAS,QAAQ,WAAW,UAAU,CAAC,CAAC;AAAA,IAChD,KAAK;AACJ,aAAO,iBAAiB,QAAQ,SAAS;AAAA,IAC1C,KAAK;AACJ,aAAO,eAAe,QAAQ,SAAS;AAAA,IACxC;AACC,aAAO,QAAQ,oBAAoB,aAAa,QAAQ,oBAAoB;AAAA,EAC9E;AACD;","names":["import_neverthrow"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Result } from 'neverthrow';
|
|
2
|
+
|
|
3
|
+
type QRParserErrorCode = "INVALID_QR" | "INVALID_CURRENCY" | "INVALID_AMOUNT" | "FETCH_FAILED";
|
|
4
|
+
declare class QRParserError extends Error {
|
|
5
|
+
readonly code: QRParserErrorCode;
|
|
6
|
+
readonly cause?: unknown;
|
|
7
|
+
readonly context?: Record<string, unknown>;
|
|
8
|
+
constructor(message: string, options: {
|
|
9
|
+
code: QRParserErrorCode;
|
|
10
|
+
cause?: unknown;
|
|
11
|
+
context?: Record<string, unknown>;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type SupportedCurrency = "INR" | "IDR" | "BRL" | "ARS" | "VEN";
|
|
16
|
+
interface ParseQRConfig {
|
|
17
|
+
proxyUrl?: string;
|
|
18
|
+
orderId?: string;
|
|
19
|
+
}
|
|
20
|
+
interface ParsedQR {
|
|
21
|
+
paymentAddress: string;
|
|
22
|
+
amount?: {
|
|
23
|
+
usdc: number;
|
|
24
|
+
fiat: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
type ParseResult = Result<ParsedQR, QRParserError>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Parses a QR string for the given currency and returns the extracted payment data.
|
|
31
|
+
*
|
|
32
|
+
* This dispatcher is `async` because dynamic PIX (BRL) QRs store the amount
|
|
33
|
+
* behind a location URL pointing at the issuing bank's PIX endpoint. The SDK
|
|
34
|
+
* resolves that URL via a CORS-bypassing proxy (see `pix-proxy` / `config.proxyUrl`),
|
|
35
|
+
* which returns a signed JWT whose `valor.original` field holds the amount.
|
|
36
|
+
* All other parsers (UPI, QRIS, MercadoPago, PagoMovil) and static PIX are
|
|
37
|
+
* synchronous and resolve immediately.
|
|
38
|
+
*/
|
|
39
|
+
declare function parseQR(qrData: string, currency: SupportedCurrency, sellPrice: number, config?: ParseQRConfig): Promise<ParseResult>;
|
|
40
|
+
|
|
41
|
+
export { type ParseQRConfig, type ParseResult, type ParsedQR, QRParserError, type QRParserErrorCode, type SupportedCurrency, parseQR };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Result } from 'neverthrow';
|
|
2
|
+
|
|
3
|
+
type QRParserErrorCode = "INVALID_QR" | "INVALID_CURRENCY" | "INVALID_AMOUNT" | "FETCH_FAILED";
|
|
4
|
+
declare class QRParserError extends Error {
|
|
5
|
+
readonly code: QRParserErrorCode;
|
|
6
|
+
readonly cause?: unknown;
|
|
7
|
+
readonly context?: Record<string, unknown>;
|
|
8
|
+
constructor(message: string, options: {
|
|
9
|
+
code: QRParserErrorCode;
|
|
10
|
+
cause?: unknown;
|
|
11
|
+
context?: Record<string, unknown>;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type SupportedCurrency = "INR" | "IDR" | "BRL" | "ARS" | "VEN";
|
|
16
|
+
interface ParseQRConfig {
|
|
17
|
+
proxyUrl?: string;
|
|
18
|
+
orderId?: string;
|
|
19
|
+
}
|
|
20
|
+
interface ParsedQR {
|
|
21
|
+
paymentAddress: string;
|
|
22
|
+
amount?: {
|
|
23
|
+
usdc: number;
|
|
24
|
+
fiat: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
type ParseResult = Result<ParsedQR, QRParserError>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Parses a QR string for the given currency and returns the extracted payment data.
|
|
31
|
+
*
|
|
32
|
+
* This dispatcher is `async` because dynamic PIX (BRL) QRs store the amount
|
|
33
|
+
* behind a location URL pointing at the issuing bank's PIX endpoint. The SDK
|
|
34
|
+
* resolves that URL via a CORS-bypassing proxy (see `pix-proxy` / `config.proxyUrl`),
|
|
35
|
+
* which returns a signed JWT whose `valor.original` field holds the amount.
|
|
36
|
+
* All other parsers (UPI, QRIS, MercadoPago, PagoMovil) and static PIX are
|
|
37
|
+
* synchronous and resolve immediately.
|
|
38
|
+
*/
|
|
39
|
+
declare function parseQR(qrData: string, currency: SupportedCurrency, sellPrice: number, config?: ParseQRConfig): Promise<ParseResult>;
|
|
40
|
+
|
|
41
|
+
export { type ParseQRConfig, type ParseResult, type ParsedQR, QRParserError, type QRParserErrorCode, type SupportedCurrency, parseQR };
|